Catch the highlights of GraphQLConf 2023! Click for recordings. Or check out our recap blog post.
Documentation
Modules
use/deno

Module: use/deno

Interfaces

Other

GRAPHQL_TRANSPORT_WS_PROTOCOL

Re-exports GRAPHQL_TRANSPORT_WS_PROTOCOL

Server/deno

makeHandler

makeHandler<P, E>(options): (socket: WebSocket) => void

Use the server with Deno. This is a basic starter, feel free to copy the code over and adjust it to your needs.

The keep-alive is set in Deno.upgradeWebSocket during the upgrade.

Additionally, the required WebSocket protocol is also defined during the upgrade, the correct example being:

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 './my-schema.ts';
 
const handler = makeHandler({ schema });
 
serve(
  (req: Request) => {
    const [path, _search] = req.url.split('?');
    if (!path.endsWith('/graphql')) {
      return new Response('Not Found', { status: 404 });
    }
    if (req.headers.get('upgrade') != 'websocket') {
      return new Response('Upgrade Required', { status: 426 });
    }
    const { socket, response } = Deno.upgradeWebSocket(req, {
      protocol: GRAPHQL_TRANSPORT_WS_PROTOCOL,
      idleTimeout: 12_000,
    });
    handler(socket);
    return response;
  },
  { port: 4000 },
);

Type parameters

NameType
Pextends undefined | Record<string, unknown> = undefined | Record<string, unknown>
Eextends Record<PropertyKey, unknown> = Record<PropertyKey, never>

Parameters

NameType
optionsServerOptions<P, Extra & Partial<E>>

Returns

fn

▸ (socket): void

Parameters
NameType
socketWebSocket
Returns

void

Defined in

src/use/deno.ts:62