-
Notifications
You must be signed in to change notification settings - Fork 133
Make a setupFunction return an object #11
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
Make a setupFunction return an object #11
Conversation
Sinon lets us assert a function is called with certian parameters.
Channel options are passed to PubSub so that we can tell it to do certain things. For instance, we could write a PubSubEngine that is capable of only listening to a subset of messages based on `channelOptions` input.
|
@quintstoffers thanks! @davidyaha do you think you could review this PR? |
|
Will do. |
davidyaha
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than those two remarks I've it looks good!
src/pubsub.ts
Outdated
| // Deconstruct the trigger options and set any defaults | ||
| let {channelOptions, filter} = trigger; | ||
|
|
||
| if (!channelOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done on line 159 like so let {channelOptions = {}, filter} = trigger;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, will fix!
src/pubsub.ts
Outdated
| const subscriptionPromises = []; | ||
| Object.keys(triggerMap).forEach( triggerName => { | ||
| // 2. generate the filter function and the handler function | ||
| const trigger = triggerMap[triggerName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no actual need for this trigger constant anymore
|
Oh also, it might be a good idea to create an inteface for the returned object on the trigger function. interface TriggerConfig {
channelOptions?: Object
filter?: Function
} |
|
@davidyaha: Thanks for your input! I removed the unnecessary variable and defined setupFunctions and children using Interfaces. |
|
You'r very welcome! I saw you decided not to use the es6 style default values, is it on purpose? Thanks for your work so far! I would like to use the improved API :) |
|
I'm not a big fan of the default values when destructuring because I often find the default values are too complex and I end up with a lump of hard to read code. I didn't give it a good thought for that reason, but it does look perfectly fine in hindsight: As a bonus the variables can now be |
|
@helfer: I think were done here 😄 . |
|
Thanks a lot! @quintstoffers @davidyaha |
|
FYI, GitHunt-API (the best way to understand how to use Apollo and graphql-subscriptions) has not yet been updated with this API change. |
See #10 for previous communication. Solves #7.
This change requires a setup function to return an object containing the properties
filterandchannelOptions. Both are optional, so no breaking changes in that regard. However, there is no backwards compatibility for the "old style" function-type return value, so existing usages need to be updated to return an object withfilterproperty.Code example taken from #10, adapted to object-style return value:
Note that I added a dev dependency to sinon to be able to assert channelOptions are passed into
pubsub.subscribe.