Skip to content

Instantly share code, notes, and snippets.

@AugustoCalaca
Created June 13, 2020 19:26
Show Gist options
  • Save AugustoCalaca/a6262676e37ca1964c1ecc3963587b17 to your computer and use it in GitHub Desktop.
Save AugustoCalaca/a6262676e37ca1964c1ecc3963587b17 to your computer and use it in GitHub Desktop.
A graphql subscription using the lib graphql-relay-subscription
import { subscriptionWithClientId } from 'graphql-relay-subscription';
import UserType from '../UserType';
import * as UserLoader from '../UserLoader';
import pubSub, { EVENTS } from '../../../channels/pubSub';
const UserAddedSubscription = subscriptionWithClientId({
name: 'UserAdded',
inputFields: {},
subscribe: () => pubSub.asyncIterator(EVENTS.USER.ADDED),
getPayload: (root) => {
return { id: root.userId };
},
outputFields: {
user: {
type: UserType,
resolve: (root, _, context) => UserLoader.load(context, root.id),
}
},
});
export default UserAddedSubscription;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment