-
-
Save iwatakeshi/02bfe7e46828bc3bf3069b4eea6725a9 to your computer and use it in GitHub Desktop.
Revisions
-
xorus created this gist
Mar 8, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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, }) })