Created
January 10, 2017 23:43
-
-
Save benwilson512/cec6d1dcfff2fabfb10035fb4c6dadd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Comment on a repository, returns the new comment | |
submitComment( | |
# The full repository name from GitHub, e.g. "apollostack/GitHunt-API" | |
repoFullName: String!, | |
# The text content for the new comment | |
commentContent: String! | |
): Comment | |
type Subscription { | |
# Subscription fires on every comment added | |
commentAdded(repoFullName: String!): Comment | |
} | |
// later in the file | |
submitComment(root, { repoFullName, commentContent }, context) { | |
return Promise.resolve() | |
.then(() => ( | |
# create comment | |
) | |
)) | |
.then((comment) => { | |
// publish subscription notification | |
pubsub.publish('commentAdded', comment); | |
return comment; | |
}); | |
}, | |
// and then in a totally separate file | |
import { PubSub, SubscriptionManager } from 'graphql-subscriptions'; | |
import schema from './schema'; | |
const pubsub = new PubSub(); | |
const subscriptionManager = new SubscriptionManager({ | |
schema, | |
pubsub, | |
setupFunctions: { | |
commentAdded: (options, args) => ({ | |
commentAdded: comment => comment.repository_name === args.repoFullName, | |
}), | |
}, | |
}); | |
export { subscriptionManager, pubsub }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment