1.0.0-beta.9
The WebSocket graphql-transport-ws sub-protocol implementation
Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
Dependencies
esm.sh
graphql-transport-ws
The WebSocket graphql-transport-ws sub-protocol implementation.
Usage
core
GraphQLTransportWs- Provides the API forgraphql-transport-wssending and receiving data.createClient- Create client-sidegraphql-transport-wssub-protocol compliant API.createServer- Create server-sidegraphql-transport-wssub-protocol compliant API.
utils
parseMessage- Parse the value asgraphql-transport-wsmessage data.createWebSocket- CreateWebSocketinstance withgraphql-transport-wssub-protocol.PROTOCOL- Sub-protocolMessageType- Definition ofgraphql-transport-wsmessage type.Status- Definition ofgraphql-transport-wsWebSocket private status code.STATUS_TEXT- A record of all the private status codes text.
Ping and Pong
Event handler property:
import { GraphQLTransportWs } from "https://deno.land/x/graphql_transport_ws@$VERSION/mod.ts";
const graphqlTransportWs = new GraphQLTransportWs("<ENDPOINT>");
graphqlTransportWs.onpong = function (ev) {
console.log(ev.data);
};
graphqlTransportWs.ping();Event listener:
import { GraphQLTransportWs } from "https://deno.land/x/graphql_transport_ws@$VERSION/mod.ts";
const graphqlTransportWs = new GraphQLTransportWs("<ENDPOINT>");
graphqlTransportWs.addEventListener("pong", (ev) => {
console.log(ev.data);
});
graphqlTransportWs.ping();
graphqlTransportWs.addEventListener("ping", () => {
graphqlTransportWs.pong();
});Connection init and Connection Ack
import { GraphQLTransportWs } from "https://deno.land/x/graphql_transport_ws@$VERSION/mod.ts";
const graphqlTransportWs = new GraphQLTransportWs("<ENDPOINT>");
graphqlTransportWs.onconnectionack = function (ev) {
console.log(ev);
};
graphqlTransportWs.connectionInit();Subscribe subscription
import { GraphQLTransportWs } from "https://deno.land/x/graphql_transport_ws@$VERSION/mod.ts";
const graphqlTransportWs = new GraphQLTransportWs("<ENDPOINT>");
graphqlTransportWs.addEventListener("connectionack", (ev) => {
console.log(ev.data);
});
graphqlTransportWs.addEventListener("next", (ev) => {
console.log(ev.data.id, ev.data.payload);
});
graphqlTransportWs.connectionInit();
graphqlTransportWs.subscribe({
query: `subscription { hello }`,
});Parse message
import {
MessageType,
parseMessage,
} from "https://deno.land/x/graphql_transport_ws@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std@$VERSION/testing/asserts.ts";
const ev = new MessageEvent("message", {
data: JSON.stringify({
type: "pong",
}),
});
const result = parseMessage(ev.data);
assertEquals(result[0], { "type": MessageType.Pong });
assertEquals(result[1], undefined);License
Copyright © 2022-present TomokiMiyauci.
Released under the MIT license
graphql-transport-ws: enisdenjo