Created
June 13, 2020 19:26
-
-
Save AugustoCalaca/a6262676e37ca1964c1ecc3963587b17 to your computer and use it in GitHub Desktop.
A graphql subscription using the lib graphql-relay-subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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