-
Notifications
You must be signed in to change notification settings - Fork 133
Pass SubscriptionOptions to PubSubEngine.subscribe #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass SubscriptionOptions to PubSubEngine.subscribe #10
Conversation
|
@quintstoffers I like the idea of passing the options to the subscribe method, but I'm a little concerned about passing everything, because I feel like it would tightly couple the PubSub subscribe function to GraphQL-specific things like the query and variables. I don't think PubSub should deal with that kind of stuff. Can you give an example of how you would use this? Could we maybe cover this by adding some functionality to |
|
@helfer I agree with what you're saying. Passing the entirety of I like the idea of expanding Perhaps something like this would work. The code example below would ask PubSub to only listen for comment updates with the given {
setupFunctions: {
// Taken from GitHunt.
commentAdded: (options, args) => ({
commentAdded: comment => comment.repository_name === args.repoFullName
}),
// Proposed structure.
commentUpdated: (options, args) => ({
commentUpdated: {
// These options could be passed to PubSub.
channelOptions: {
repoFullName: args.repoFullName
},
// Technically redundant since we specified repoFullName above and thus should
// only receive relevant messages. However, it's here for completeness' sake
filter: comment => comment.repository_name === args.repoFullName
}
})
}
}Thanks to By passing an Object we can also expand in the future. In fact, I'd be very interested in being able to specify a |
|
@quintstoffers That sounds good. If anything, I think it should always return an object, and make filter optional as well (in which case it will default to true). Would you have time to make a PR with that change? For converting the message payload, you can actually use the resolve function of the subscription, which usually does nothing other than pass through the rootValue. That's assuming the payload looks the same for all your channels. If it doesn't, we might indeed want to add something like that. But let's keep that for a later time. |
|
@helfer I'm pretty sure I'll be able to have a PR some time next week. I hope my TypeScript is up to scratch 😉. Do you think we should support the "old" format that returned a function and thus be backwards compatiblr? We can detect the function type and convert it to an object with the |
|
@quintstoffers: Great, I look forward to it! As for backwards compatibility, I don't think we should have that. It's too early in the project to incur the kind of technical debt that backwards compatibility usually brings with it. |
See /issues/7
By passing the SubscriptionOptions to the PubSubEngine it can in turn create more specific subscriptions to sources such as RabbitMQ and rethinkDB.
For example, assume that we are interested in updates to a specific comment. We could listen to all comment updates and use our filter function to only send the relevant updates to the client. However, this assumes that it's feasible to listen to all comment updates on our Apollo server in the first place.
By allowing PubSubEngine.subscribe access to SubscriptionOptions it could listen for exactly the subset of comment updates the client requested. For instance, by subscribing to the RabbitMQ channel
updates.comments.COMMENT_IDas opposed toupdates.comments.