-
Notifications
You must be signed in to change notification settings - Fork 842
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
Add Subscribe function to make easier to create Subscription Handlers #530
Conversation
@chris-ramon that's a quick hack to be able to do better subscriptions. There are other PRs about it (like #495 ) but this one is pretty simple and fast to review. I just add a Subscription parameter so the handler can use it and have better code. |
Nice job!! Any prediction of when it will be accept/merged? |
I'm also interested in this change. Any news? |
Instead of using a different subscribe functions we should use a channel to send events and return this channel as resolver return value Gqlgen and graphql gophers already do this, I don’t like the approach of this pr, it is not intuitive and difficult to integrate with pubsub libs |
@@ -368,12 +369,15 @@ type IsTypeOfFn func(p IsTypeOfParams) bool | |||
|
|||
type InterfacesThunk func() []*Interface | |||
|
|||
type SubscribeFn func(p ResolveParams) error |
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.
this is the same function signature as a FieldResolveFn, any reason not to just use that?
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.
Wouldn't it be more user friendly to assign this under a name which includes "Subscription" in it? Like, if you wanna search for the particular subscription handler for subscription, its easy to identify it. Could be wrong.
I gave a longer answer in my PR but the short version is that this project follows the reference implementation which has this method https://github.com/graphql/graphql-js/blob/master/src/type/definition.js#L1001 . It it also not difficult to integrate into pubsub libs if you implement the Subscribe handler https://github.com/graphql/graphql-js/blob/master/src/subscription/subscribe.js#L63 |
ok i think we can close this in favour of #495 |
I added Subscribe function to Object / Fields Definitions so its easier to make GraphQL Subscription Handlers. I only added the field so it wouldn't break compatibility and if you don't use it, it wont make a difference.
So for example in https://github.com/racerxdl/go-subscription-handler I did:
With that
Subscribe
field in the struct I could do:That should help with #242