
Product
Reachability for Ruby Now in Beta
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.
@soundxyz/graphql-react-ws
Advanced tools
[](https://www.npmjs.com/package/@soundxyz/graphql-react-ws)
GraphQLReactWS – React GraphQL Subscriptions with graphql-ws and ValtioA React utility for managing GraphQL subscriptions over WebSockets, with Valtio-powered state and effect hooks.
Feel free to check out full end-to-end example in examples/next/src/pages/subscription.tsx
import { GraphQLReactWS } from './GraphQLReactWS';
import { createClient } from 'graphql-ws';
const wsClientOptions = {
url: 'wss://your-graphql-endpoint/graphql',
// ...other options
};
const graphql = GraphQLReactWS({ graphqlWsOptions: wsClientOptions });
GraphQLReactWSconst graphql = GraphQLReactWS({ graphqlWsOptions });
graphqlWsOptions: Options for the graphql-ws client.client graphql-ws clientsubscribe subscribe to a GraphQL subscriptionuseSubscription React hook to subscribe to a GraphQL subscriptionsubscriptionStores Map of subscription storessetSubscriptionData Manually set the data for a subscription storegetSubscriptionStore Get a subscription storeEffects Register global effects for when data arrives or a subscription completesuseSubscriptionA React hook to subscribe to a GraphQL subscription and reactively receive data and errors.
const { data, error, store } = graphql.useSubscription({
query: MySubscriptionDocument,
variables: { id: '123' }, // optional if your subscription has no variables
onData: result => {
/* handle new data */
},
onError: error => {
/* handle errors */
},
enabled: true, // optional, default true
});
Parameters:
query: The GraphQL subscription document.variables: (optional) Variables for the subscription.onData: (optional) Callback for new data.onError: (optional) Callback for errors.initialData: (optional) Initial data for the store.enabled: (optional) Whether the subscription is active.Returns:
data: Latest subscription data.error: Latest error, if any.store: The underlying Valtio store.setSubscriptionDataManually set the data for a subscription store.
graphql.setSubscriptionData(
{ query: MySubscriptionDocument, variables: { id: '123' } },
{ data: { ... } }
);
query: The GraphQL subscription document.variables: (optional) Variables for the subscription.data: The new data to set.EffectsRegister global effects for when data arrives or a subscription completes.
Effects.onDataRegister a callback to be called every time the specified operation receives data.
const remove = Effects.onData(MySubscriptionDocument, ({ operation, result, variables }) => {
// Do something with result.data
});
Effects.onCompleteRegister a callback to be called when the specified operation completes or is stopped.
const remove = Effects.onComplete(MySubscriptionDocument, ({ operation, variables }) => {
// Do something on completion
});
const { data, error } = useSubscription({
query: MySubscriptionDocument,
variables: { id: 'abc' },
onData: result => {
console.log('New data:', result.data);
},
onError: err => {
console.error('Subscription error:', err.errors);
},
});
const removeEffect = Effects.onData(MySubscriptionDocument, ({ result }) => {
console.log('Received data:', result.data);
});
// Later, to remove the effect:
removeEffect();
graphql.setSubscriptionData(
{ query: MySubscriptionDocument, variables: { id: 'abc' } },
{ data: { myField: 'newValue' } },
);
FAQs
Unknown package
We found that @soundxyz/graphql-react-ws demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 15 open source maintainers 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.

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.

Research
/Security News
Malicious npm packages use Adspect cloaking and fake CAPTCHAs to fingerprint visitors and redirect victims to crypto-themed scam sites.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.