Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@enisdenjo/graphql-transport-ws
Advanced tools
🔗 A coherent, zero-dependency, lazy, simple and easy to use server and client implementation of the GraphQL over WebSocket Protocol.
yarn add @enisdenjo/graphql-transport-ws
# or
npm install @enisdenjo/graphql-transport-ws
import { createClient } from '@enisdenjo/graphql-transport-ws';
import { Network, Observable } from 'relay-runtime';
const subscriptionsClient = createClient({
url: 'wss://some.url/graphql',
connectionParams: () => {
const session = getSession();
if (!session) {
return null;
}
return {
Authorization: `Bearer ${session.token}`,
};
},
});
export const network = Network.create(
// fetch
(operation, variables, cacheConfig) => {
return Observable.create((sink) => {
fetchQuery(operation, variables, cacheConfig, sink);
});
},
// subscribe
(operation, variables) => {
return Observable.create((sink) => {
if (!operation.text) {
return sink.error(new Error('Operation text cannot be empty'));
}
return subscriptionsClient.subscribe(
{
operationName: operation.name,
query: operation.text,
variables,
},
sink,
);
});
},
);
import { print } from 'graphql';
import { ApolloLink, Operation, FetchResult, Observable } from '@apollo/client';
import { createClient, Config, Client } from '@enisdenjo/graphql-transport-ws';
class WebSocketLink extends ApolloLink {
private client: Client;
constructor(config: Config) {
super();
this.client = createClient(config);
}
public request({
operationName,
query,
variables,
}: Operation): Observable<FetchResult> {
return new Observable((sink) => {
return this.client.subscribe<FetchResult>(
{ operationName, query: print(query), variables },
sink,
);
});
}
}
const link = new WebSocketLink({
url: 'wss://some.url/graphql',
connectionParams: () => {
const session = getSession();
if (!session) {
return null;
}
return {
Authorization: `Bearer ${session.token}`,
};
},
});
TypeDoc generated documentation is located in the docs folder.
Read about the exact transport protocol used by the library in the PROTOCOL.md document.
File a bug, contribute with code, or improve documentation? Welcome 👋! Read up on our guidelines for contributing.
1.0.2 (2020-08-26)
Package has been renamed from graphql-transport-ws
to graphql-ws
.
FAQs
A WebSocket client for GraphQL subscriptions
The npm package @enisdenjo/graphql-transport-ws receives a total of 6 weekly downloads. As such, @enisdenjo/graphql-transport-ws popularity was classified as not popular.
We found that @enisdenjo/graphql-transport-ws demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.