diff --git a/src/use/deno.ts b/src/use/deno.ts index e2b86a1a..1d8935aa 100644 --- a/src/use/deno.ts +++ b/src/use/deno.ts @@ -28,18 +28,18 @@ export interface Extra { * the correct example being: * * ```ts - * import { serve } from "https://deno.land/std/http/mod.ts"; + * import { serve } from 'https://deno.land/std/http/mod.ts'; * import { * makeHandler, * GRAPHQL_TRANSPORT_WS_PROTOCOL, - * } from "graphql-ws/lib/use/deno"; - * import { schema } from "./my-schema.ts"; + * } from 'https://esm.sh/graphql-ws/lib/use/deno'; + * import { schema } from './my-schema.ts'; * * const handler = makeHandler({ schema }); * * serve( * (req: Request) => { - * if (req.headers.get("upgrade") != "websocket") { + * if (req.headers.get('upgrade') != 'websocket') { * return new Response(null, { status: 501 }); * } * const { socket, response } = Deno.upgradeWebSocket(req, { @@ -49,7 +49,7 @@ export interface Extra { * handler(socket); * return response; * }, - * { port: 4000 } + * { port: 4000 }, * ); * ``` * diff --git a/website/src/pages/get-started.mdx b/website/src/pages/get-started.mdx index b83c152f..d34bcc2d 100644 --- a/website/src/pages/get-started.mdx +++ b/website/src/pages/get-started.mdx @@ -141,6 +141,34 @@ Bun.serve({ console.log('Listening to port 4000'); ``` +#### With [Deno](https://deno.com/runtime) + +```ts +import { serve } from 'https://deno.land/std/http/mod.ts'; +import { + makeHandler, + GRAPHQL_TRANSPORT_WS_PROTOCOL, +} from 'https://esm.sh/graphql-ws/lib/use/deno'; +import { schema } from './previous-step.ts'; + +const handler = makeHandler({ schema }); + +serve( + (req: Request) => { + if (req.headers.get('upgrade') != 'websocket') { + return new Response(null, { status: 501 }); + } + const { socket, response } = Deno.upgradeWebSocket(req, { + protocol: GRAPHQL_TRANSPORT_WS_PROTOCOL, + idleTimeout: 12_000, + }); + handler(socket); + return response; + }, + { port: 4000 }, +); +``` + ### Use the client ```ts