GraphQL client and handler compliant with GraphQL over WebSocket specification
Create Request
handler compliant GraphQL over WebSocket server.
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);
(req: Request) => Response
-
AggregateError
When GraphQL schema validation error has occurred.
Create GraphQL over WebSocket client.
import { createClient } from "https://deno.land/x/graphql_websocket@$VERSION/mod.ts";
const Client = createClient(`wss://<ENDPOINT>`);
Name | Required | Description |
---|---|---|
url | ✅ | string | URL The URL to which to connect; this should be the URL to which the WebSocket server will respond. |
GraphQL over WebSocket client specification.
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 }`,
});