@4c/graphql-relay-subscription
v0.4.0
Published
Relay subscription helpers for GraphQL.js
Downloads
18
Readme
graphql-relay-subscription
Relay subscription helper for GraphQL.js.
Usage
As with mutationWithClientId
in graphql-relay-js, subscriptionWithClientId
creates subscriptions with single inputs and client subscription IDs.
import { parse, subscribe } from 'graphql';
import { subscriptionWithClientId } from 'graphql-relay-subscription';
/* ... */
const UpdateWidgetSubscription = subscriptionWithClientId({
name: 'UpdateWidgetSubscription',
inputFields: {
widgetId: { type: GraphQLString },
},
outputFields: {
widget: Widget,
},
subscribe: ({ widgetId }) =>
createSubscription(`widgets:${widgetId}:updated`),
});
const subscription = await subscribe(
schema,
parse(`
subscription ($input_0: UpdateWidgetSubscriptionInput!) {
updateWidget(input: $input_0) {
widget {
name
}
clientSubscriptionId
}
}
`),
null,
null,
{
input_0: {
widgetId: 'foo',
clientSubscriptionId: '0',
},
},
);