Skip to content

Instantly share code, notes, and snippets.

@iwatakeshi
Forked from xorus/aaa.ts
Created February 10, 2025 15:42
Show Gist options
  • Save iwatakeshi/02bfe7e46828bc3bf3069b4eea6725a9 to your computer and use it in GitHub Desktop.
Save iwatakeshi/02bfe7e46828bc3bf3069b4eea6725a9 to your computer and use it in GitHub Desktop.

Revisions

  1. @xorus xorus created this gist Mar 8, 2023.
    35 changes: 35 additions & 0 deletions aaa.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    import {Env, Hono, HonoRequest} from "hono";
    import {createSchema, createYoga} from "graphql-yoga";

    const schema = createSchema({
    typeDefs: `...graphql schema...`,
    resolvers: {
    Query: {
    hello: () => 'Hello wolrd :)',
    },
    Subscription: {
    countdown: {
    subscribe: async function* (_, {from}) {
    for (let i = from; i >= 0; i--) {
    await new Promise((resolve) => setTimeout(resolve, 1000))
    yield {countdown: i}
    }
    }
    }
    }
    }
    })

    const yoga = createYoga({
    schema,
    graphqlEndpoint: '/api/graphql',
    });

    // adapted from https://github.com/hagishi/hono-graphql-yoga that was not updated
    app.use('/api/graphql', async (c) => {
    const ctx = Object.prototype.hasOwnProperty.call(c, 'executionCtx') ? c.executionCtx : {}
    return yoga.handleRequest(c.req, {
    env: c.env,
    ctx,
    })
    })