Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@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.1.0 (2020-08-28)
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 8 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.