-
Notifications
You must be signed in to change notification settings - Fork 18
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
subscription support #12
Comments
That's right. This package doesn't have any additional GraphQL subscription functionality. But as the underlying Graphiti and GraphQL packages support subscriptions, you can always use these to implement them in your application. |
Thanks. I looked into this for a few hours, and I don't think I'm going to tackle it right now, it's just a bit above my skill set currently. But if I gain some clarity and understanding in the future, I'd really like to convert my web-socket functionality to GraphQL subscriptions, so I may take a crack at it later. The underlying mechanisms provided by the Graphiti and GraphQL packages are only scantily documented. I read and re-read the source for those a bunch of times. I think I got a very basic mental model of how it works -- your resolver needs to return a Future of an I'm going to implement vanilla web-sockets without GraphQL in my vapor app for now, and my hope is that as my comfort level with those grows (this is my first production implementation of web sockets), and as I learn more about Combine, I might see a way forward. In the meantime, if you ever want to work on this feature, I'd be happy to try to help, or do some remote pair programming. Really appreciate this library. |
Sure, I can provide a little insight. I did build my final app using the normal Vapor websocket implementation, but I didn't use this package - just Graphiti. In terms of connecting up the observables to websockets, it's not too bad. The steps are this:
In my implementation, I copied the protocol used by the javascript graphql-ws to formalize the websocket handshake and make it work with GraphiQL. The small GraphQLRxSwift package is a wrapper around RxSwift's PubSub functionality - it should be almost exactly the same for a |
@NeedleInAJayStack really appreciate you taking the time to chime in. 🙏 So, is there a single, shared, singleton-like publisher for your whole app that publishes when something happens (via the SQL trigger)? Do you then end up basically filtering over the single publisher and emitting events interesting to given web-socket clients based on what they subscribed to? Or am I misunderstanding, and does each client websocket connection get its own un-shared publisher based on the subscription? I don't suppose there's any chance your app is open source somewhere where I could poke around the code a bit? If not, would you mind copy/pasting a few lines of the relevant code for each step you mentioned above? Thanks again! |
No problem!
No, we create a fresh PublishSubject in each GraphQL subscription resolver. This is because we want to create and setup SQL triggers based only on what clients have asked for, and then just wrap their callbacks with RxSwift. Yea, the GraphQLRxSwift tests are a little confusing in this case because they use a global PublishSubject because the tests need to have an external handle to cause an event.
Yes, this is what we do.
Unfortunately it's closed source. The Graphiti GraphQLRxSwift tests are pretty close to what we are doing though, except that in the subscribe resolver we create the Hope that helps! |
Thanks a lot @NeedleInAJayStack, that helps a lot. |
It looks like this library in its current form doesn't support GraphQL subscriptions. Is that correct? I'm wanting to implement some new websocket-based functionality in one of my vapor/graphql apps, and I'm trying to get a feel for how much work it would be to keep it purely graphql, or whether I should just build this feature outside of graphql for now. I know the Graphiti library has some support for subscriptions, by subclassing
EventStream
from the coreGraphQL
library.have you thought about this at all, or do you have any plans on implementing this? or thoughts on how it would be accomplished? if the path forward seemed not to crazy, i thought maybe i could possibly try an initial implementation, if it was something you were interested in adding support for, or could possibly give me a pointer or two how you'd like to see it implemented in the context of this library.
The text was updated successfully, but these errors were encountered: