Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@carlosdp/socket-io-graphql-client
Advanced tools
[![npm version](https://img.shields.io/npm/v/@n1ru4l/socket-io-graphql-client.svg)](https://www.npmjs.com/package/@n1ru4l/socket-io-graphql-client) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/socket-io-graphql-client.svg)](https://www.npmjs.co
Execute GraphQL operations against a @n1ru4l/socket-io-graphql-server
instance.
If you want to see usage we recommend checking out the example clients for relay, apollo and urql!
yarn add -E @n1ru4l/socket-io-graphql-client
createSocketIOGraphQLClient
import { io } from "socket.io-client";
import { createSocketIOGraphQLClient } from "@n1ru4l/socket-io-graphql-client";
const socket = io();
const socketIOGraphQLClient = createSocketIOGraphQLClient(socket);
{
// execute returns a AsyncIterable that will publish the values for the operation
const asyncIterator = socketIOGraphQLClient.execute({
operation: /* GraphQL */ `
query messages {
id
content
}
`,
});
for await (const value of asyncIterator) {
console.log(value);
}
}
{
const asyncIterator = socketIOGraphQLClient.execute({
operation: /* GraphQL */ `
query messages @live {
id
content
}
`,
});
for await (const value of asyncIterator) {
console.log(value);
}
}
{
const asyncIterator = socketIOGraphQLClient.execute(
{
operation: /* GraphQL */ `
subscription onNewMessage {
onNewMessage {
id
content
}
}
`,
}
);
// dispose subscription in 5 seconds
setTimeout(() => asyncIterator.return.?(), 5000);
for await (const value of asyncIterator) {
console.log(value);
}
}
import { io } from "socket.io-client";
import { createSocketIOGraphQLClient } from "@n1ru4l/socket-io-graphql-client";
import { applyAsyncIterableIteratorToSink } from "@n1ru4l/push-pull-async-iterable-iterator";
import "graphiql/graphiql.css";
import GraphiQL from "graphiql";
const socket = io();
const socketIOGraphQLClient = createSocketIOGraphQLClient(socket);
const fetcher: Fetcher = ({ query: operation, ...restGraphQLParams }: any) =>
socketIOGraphQLClient.execute({
operation,
...restGraphQLParams,
});
export const LiveGraphiQL = (): React.ReactElement => (
<GraphiQL fetcher={fetcher} />
);
As used in the relay todo example app
(https://github.com/n1ru4l/graphql-live-queries/tree/main/packages/todo-example/client-relay).
import { SocketIOGraphQLClient } from "@n1ru4l/socket-io-graphql-client";
import { applyAsyncIterableIteratorToSink } from "@n1ru4l/push-pull-async-iterable-iterator";
import {
Environment,
Network,
RecordSource,
Store,
Observable,
GraphQLResponse,
RequestParameters,
Variables,
} from "relay-runtime";
export const createRelayEnvironment = (
networkInterface: SocketIOGraphQLClient<GraphQLResponse, Error>
) => {
const execute = (request: RequestParameters, variables: Variables) => {
if (!request.text) throw new Error("Missing document.");
const { text: operation, name } = request;
return Observable.create<GraphQLResponse>((sink) =>
applyAsyncIterableIteratorToSink(
networkInterface.execute({
operation,
variables,
operationName: name,
}),
sink
)
);
};
const network = Network.create(execute, execute);
const store = attachNotifyGarbageCollectionBehaviourToStore(
new Store(new RecordSource())
);
return new Environment({
network,
store,
});
};
As used in the apollo client todo example app
(https://github.com/n1ru4l/graphql-live-queries/tree/main/packages/todo-example/client-apollo).
import { SocketIOGraphQLClient } from "@n1ru4l/socket-io-graphql-client";
import { applyAsyncIterableIteratorToSink } from "@n1ru4l/push-pull-async-iterable-iterator";
import {
ApolloClient,
InMemoryCache,
ApolloLink,
Operation,
Observable,
FetchResult,
Observable,
} from "@apollo/client";
import { print } from "graphql";
class SocketIOGraphQLApolloLink extends ApolloLink {
private networkLayer: SocketIOGraphQLClient;
constructor(networkLayer: SocketIOGraphQLClient) {
super();
this.networkLayer = networkLayer;
}
public request(operation: Operation): Observable<FetchResult> | null {
return new Observable((sink) =>
applyAsyncIterableIteratorToSink(
this.networkLayer.execute({
operationName: operation.operationName,
operation: print(operation.query),
variables: operation.variables,
}),
sink
)
);
}
}
export const createApolloClient = (networkInterface: SocketIOGraphQLClient) => {
return new ApolloClient({
link: new SocketIOGraphQLApolloLink(networkInterface),
cache: new InMemoryCache(),
});
};
As used in the urql todo example app
(https://github.com/n1ru4l/graphql-live-queries/tree/main/packages/todo-example/client-urql).
import { SocketIOGraphQLClient } from "@n1ru4l/socket-io-graphql-client";
import { applyAsyncIterableIteratorToSink } from "@n1ru4l/push-pull-async-iterable-iterator";
import {
Client,
dedupExchange,
cacheExchange,
subscriptionExchange,
ExecutionResult,
} from "urql";
export const createUrqlClient = (
networkInterface: SocketIOGraphQLClient<ExecutionResult>
) => {
return new Client({
url: "noop",
exchanges: [
dedupExchange,
cacheExchange,
subscriptionExchange({
forwardSubscription: (operation) => ({
subscribe: (sink) => ({
unsubscribe: applyAsyncIterableIteratorToSink(
networkInterface.execute({
operation: operation.query,
variables: operation.variables,
}),
sink
),
}),
}),
enableAllOperations: true,
}),
],
});
};
FAQs
[![npm version](https://img.shields.io/npm/v/@n1ru4l/socket-io-graphql-client.svg)](https://www.npmjs.com/package/@n1ru4l/socket-io-graphql-client) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/socket-io-graphql-client.svg)](https://www.npmjs.co
The npm package @carlosdp/socket-io-graphql-client receives a total of 2 weekly downloads. As such, @carlosdp/socket-io-graphql-client popularity was classified as not popular.
We found that @carlosdp/socket-io-graphql-client 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.