graphql-websocket

deno land deno doc codecov

GraphQL client and handler compliant with GraphQL over WebSocket specification.

API

createHandler

Create Request handler compliant GraphQL over WebSocket server.

Example

import { createHandler } from "https://deno.land/x/graphql_websocket@$VERSION/mod.ts";
import { serve } from "https://deno.land/std@$VERSION/http/mod.ts";
import { buildSchema } from "https://esm.sh/graphql@$VERSION";

const handler = createHandler({
  schema: buildSchema(`type Query { hello: String }
type Subscription {
  greetings: String!
}`),
  rootValue: {
    greetings: async function* () {
      for (const hi of ["Hi", "Bonjour", "Hola", "Ciao", "Zdravo"]) {
        yield { greetings: hi };
      }
    },
  },
});

serve(handler);

ReturnType

(req: Request) => Response

Throws

  • AggregateError

    When GraphQL schema validation error has occurred.

createClient

Create GraphQL over WebSocket client.

Example

import { createClient } from "https://deno.land/x/graphql_websocket@$VERSION/mod.ts";

const Client = createClient(`wss://<ENDPOINT>`);

Parameters

Name Required Description
url :white_check_mark: string | URL
The URL to which to connect; this should be the URL to which the WebSocket server will respond.

ReturnType

Client

Client

GraphQL over WebSocket client specification.

Example

import { createClient } from "https://deno.land/x/graphql_websocket@$VERSION/mod.ts";

const Client = createClient(`wss://<ENDPOINT>`);
Client.addEventListener("next", ({ data }) => {
  console.log(data);
});

Client.subscribe({
  query: `subscription { test }`,
});

License

Copyright © 2022-present TomokiMiyauci.

Released under the MIT license