Registry / devops / apollo-client-ws

apollo-client-ws

JSON →
library2.6.1jsnpmunverified

Apollo Client WebSocket network link for GraphQL operations. Current stable version 2.6.1, released 2021-05-11, no regular releases since. Provides a WebSocket-based ApolloLink alternative to apollo-link-ws/subscriptions-transport-ws. Features deferred connection, keepalive, and custom messaging. Uses a custom framed protocol (WebSocket-Framed) instead of subscriptions-transport-ws protocol. Requires apollo-client >=2.1.0 and apollo-link >=1.0.7 as peer dependencies. Node >=8.0.0 required. Not subscription-oriented.

npm install apollo-client-ws
INSTALL
IMPORT
SIG · APOLLO-CLIENT-WS
A
apollo-client-ws
devopsjavascriptv2.6.1
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.

ApolloClientWS
const { ApolloClientWS } = require('apollo-client-ws')
import { ApolloClientWS } from 'apollo-client-ws'
Package is CJS-only, no ESM export. ESM import will fail.
ApolloClient
const { ApolloClient } = require('apollo-client')
const ApolloClient = require('apollo-client-ws')
ApolloClient is from apollo-client, not apollo-client-ws. Common mistake to import from wrong package.
gql
const gql = require('graphql-tag')
const { gql } = require('graphql-tag')
graphql-tag exports default function, not named export.

Creates a WebSocket link for Apollo Client and runs a simple query.

const gql = require('graphql-tag'); const { ApolloClient } = require('apollo-client'); const { ApolloClientWS } = require('apollo-client-ws'); const { InMemoryCache } = require('apollo-cache-inmemory'); const link = new ApolloClientWS({ uri: 'ws://127.0.0.1:12345/api', opts: { keepalive: 30000, reconnect: true, reconnectAttempts: 10, reconnectDelay: 2000 } }); const client = new ApolloClient({ link, cache: new InMemoryCache() }); client.query({ query: gql`{ __typename }` }) .then(response => console.log(response)) .catch(err => console.error(err));
Debug
Known issues
breakingNode.js >=8.0.0 required. Older versions are unsupported and may cause runtime errors.
fix
Use Node.js >=8.0.0 or polyfill missing features.
affects: <8
gotchaUses non-standard framed protocol (WebSocket-Framed). Not compatible with subscriptions-transport-ws servers.
fix
Ensure server speaks WebSocket-Framed protocol or use apollo-link-ws.
affects: *
deprecatedPackage is not actively maintained; last release 2021. Not recommended for new projects.
fix
Consider using @apollo/client with built-in WebSocket support or apollo-link-ws.
affects: *
Errors
Common errors & fixes
Cannot find module 'apollo-client-ws'
Package not installed or misspelled.
fix
Run: npm install apollo-client-ws
Missing class name 'ApolloClientWS' (import not a constructor)
Attempting ESM import from CJS-only package.
fix
Use const { ApolloClientWS } = require('apollo-client-ws');
Upgrade
Version history
2.6.1latest on npm
Audit
Dependencies
apollo-clientrequiredPeer dependency - core Apollo Client library
apollo-linkrequiredPeer dependency - Apollo Link interface
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
apollo-client-ws — npm install apollo-client-ws · libregistry