Registry / messaging / graphql-subscriptions-client

graphql-subscriptions-client

JSON →
library0.16.4jsnpmunverified

A lightweight, rollup-compatible GraphQL subscription client based on subscriptions-transport-ws protocol. Version 0.16.4. It uses native WebSockets, requires queries as strings (no graphql-tag support), and includes automatic reconnection. No dependencies. Suitable for modern browsers and non-Apollo setups. Consider using graphql-ws instead for a more maintained alternative.

npm install graphql-subscriptions-client
INSTALL
IMPORT
SIG · GRAPHQL-SUBSCRIPTI
G
graphql-subscriptions-client
messagingjavascriptv0.16.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SubscriptionClient
import { SubscriptionClient } from 'graphql-subscriptions-client'
const { SubscriptionClient } = require('graphql-subscriptions-client')
Package exports ESM; CommonJS require may not work depending on bundler. Default import works, but named import is preferred.

Shows how to create a SubscriptionClient, perform a subscription, and handle incoming data with automatic reconnection.

import { SubscriptionClient } from 'graphql-subscriptions-client'; const GRAPHQL_ENDPOINT = "ws://localhost:3000/graphql"; const query = `subscription onNewItem { newItemCreated { id } }`; const client = new SubscriptionClient(GRAPHQL_ENDPOINT, { reconnect: true, lazy: true, connectionCallback: (error) => { error && console.error(error); }, }); const subscription = client.request({ query }).subscribe({ next({ data }) { if (data) { console.log("We got something!", data); } }, }); // Later: subscription.unsubscribe();
Debug
Known issues
gotchaQuery must be a string; graphql-tag's gql template literal is not supported.
fix
Pass queries as plain strings, e.g., `const query = 'subscription { ... }'`.
affects: >=0.1.0
gotchaOnly native WebSocket is used; not compatible with older browsers or polyfills.
fix
Ensure target browsers support WebSocket, or provide a polyfill before importing.
affects: >=0.1.0
gotchaDo not use with apollo-client; this library is meant for standalone subscription usage.
fix
Use subscriptions-transport-ws or graphql-ws if integrating with Apollo Client.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: client.request(...).subscribe is not a function
Attempting to call `.subscribe()` on the return value when `request` is not called or when `subscribe` is not imported from rxjs.
fix
Ensure you import `subscribe` from rxjs (e.g., `import { subscribe } from 'rxjs'`) and that `client.request({ query })` is called before `.subscribe()`.
Module not found: Can't resolve 'graphql-subscriptions-client'
Package not installed or wrong import path.
fix
Run `npm install graphql-subscriptions-client` and check import statement: `import { SubscriptionClient } from 'graphql-subscriptions-client'`.
Upgrade
Version history
0.16.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
2
Resources
graphql-subscriptions-client — npm install graphql-subscriptions-client · libregistry