Skip to content

GraphQL client and handler compliant with GraphQL over WebSocket specification

Notifications You must be signed in to change notification settings

graphqland/graphql-websocket

Repository files navigation

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 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 }`,
});

About

GraphQL client and handler compliant with GraphQL over WebSocket specification

Resources

Stars

Watchers

Forks

Packages

No packages published