Registry / messaging / apollo-link-ws

apollo-link-ws

JSON →
library1.0.20jsnpmunverified

Apollo Link WebSocket is a link for Apollo Client enabling GraphQL operations over WebSocket, specifically designed for subscriptions. The latest stable version is 1.0.20, released in March 2019. It is part of the Apollo Link ecosystem and relies on subscriptions-transport-ws (^0.9.0) as a peer dependency. Its key differentiator is seamless integration with Apollo Client for real-time GraphQL subscriptions, but it also supports queries and mutations over WebSocket. Note that development has shifted to the @apollo/client package since Apollo Client 3.0, rendering this package deprecated in favor of the built-in WebSocket support in @apollo/client.

npm install apollo-link-ws
INSTALL
IMPORT
SIG · APOLLO-LINK-WS
A
apollo-link-ws
messagingjavascriptv1.0.20
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.

WebSocketLink
import { WebSocketLink } from 'apollo-link-ws'
const { WebSocketLink } = require('apollo-link-ws')
The package is ESM-friendly but also supports CJS require. However, WebSocketLink is a named export, not a default export.
WebSocketLink
const { WebSocketLink } = require('apollo-link-ws')
const WebSocketLink = require('apollo-link-ws').default
CommonJS require must destructure the named export. There is no default export.
WebSocketLink constructor
new WebSocketLink(client)
new WebSocketLink({ uri: 'ws://...' })
The link accepts either a SubscriptionClient instance or a configuration object with 'uri', 'options', and 'webSocketImpl'. Passing a plain object directly is correct if you provide the right keys, but common mistake is passing only a URI string.

Shows how to create a WebSocketLink using a SubscriptionClient and use it with Apollo Client.

import { WebSocketLink } from 'apollo-link-ws'; import { SubscriptionClient } from 'subscriptions-transport-ws'; const client = new SubscriptionClient('ws://localhost:4000/graphql', { reconnect: true }); const link = new WebSocketLink(client); // Use the link in Apollo Client const apolloClient = new ApolloClient({ link: link, cache: new InMemoryCache() });
Debug
Known issues
deprecatedapollo-link-ws is deprecated in favor of built-in WebSocket support in @apollo/client 3+
fix
Migrate to @apollo/client and use split with HttpLink and WebSocketLink from '@apollo/client/link/ws'
affects: >=1.0.0
breakingVersion 1.0.0 changed the constructor to accept a SubscriptionClient or configuration object instead of just an object with uri and options.
fix
Update to new constructor syntax: new WebSocketLink(client) or new WebSocketLink({ uri: ... })
affects: <1.0.0
gotchaUsing the default export (import WebSocketLink from 'apollo-link-ws') results in undefined at runtime because there is no default export.
fix
Use named import: import { WebSocketLink } from 'apollo-link-ws'
affects: >=1.0.0
gotchaThe package requires the peer dependency subscriptions-transport-ws. Not installing it will cause runtime errors like 'Cannot find module...'
fix
Install subscriptions-transport-ws as a dependency: npm install subscriptions-transport-ws
affects: >=1.0.0
deprecatedsubscriptions-transport-ws is unmaintained and has known security issues; consider using graphql-ws instead.
fix
Migrate to graphql-ws and update the link or use @apollo/client's built-in WebSocket link
affects: >=0.9.0
Errors
Common errors & fixes
Error: Cannot find module 'apollo-link-ws'
Package not installed.
fix
Run npm install apollo-link-ws
TypeError: WebSocketLink is not a constructor
Using the default import which is undefined.
fix
Use named import: import { WebSocketLink } from 'apollo-link-ws'
Cannot read property 'request' of undefined
SubscriptionClient not passed or incorrectly configured.
fix
Ensure you pass a valid SubscriptionClient instance: new SubscriptionClient('ws://...', { reconnect: true })
Upgrade
Version history
1.0.20latest on npm
Audit
Dependencies
subscriptions-transport-wsrequiredRequired peer dependency for WebSocket transport functionality
Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
apollo-link-ws — npm install apollo-link-ws · libregistry