Skip to content

Instantly share code, notes, and snippets.

@benwilson512
Created January 10, 2017 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benwilson512/cec6d1dcfff2fabfb10035fb4c6dadd0 to your computer and use it in GitHub Desktop.
Save benwilson512/cec6d1dcfff2fabfb10035fb4c6dadd0 to your computer and use it in GitHub Desktop.
# 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