diff --git a/README.md b/README.md index 40f041e4..6e689a27 100644 --- a/README.md +++ b/README.md @@ -689,6 +689,41 @@ function createPingerClient(options: ClientOptions): PingerClient { +
+🔗 Client usage supported check + +```ts +import { createClient } from 'graphql-ws'; + +function supportsGraphQLTransportWS(url: string): Promise { + return new Promise((resolve) => { + const client = createClient({ + url, + retryAttempts: 0, // fail immediately + lazy: false, // connect as soon as the client is created + on: { + closed: () => resolve(false), // connection rejected, probably not supported + connected: () => { + resolve(true); // connected = supported + client.dispose(); // dispose after check + }, + }, + }); + }); +} + +const supported = await supportsGraphQLTransportWS( + 'ws://some.unknown:4000/enpoint', +); +if (supported) { + // use graphql-ws +} else { + // fallback (use subscriptions-transport-ws?) +} +``` + +
+
🔗 Client usage in browser