[Feature] Support for subscription
alexstrat opened this issue · 1 comments
As noted in Readme, today's implementation does not support subscriptions and it is, a priori, not a big deal because as noted in Readme:
in
reactive-graphql
everything is treated as subscriptions
Though, I figured out some benefits of having support for proper GraphQL Subscriptions:
Support conceptual difference between live queries and subscription
There is a conceptual difference between live queries and subscription that is well summarized with:
Live Queries observe data, subscriptions observe events
I stumbled upon cases where I specifically want to react to events. Example: to trigger some animations in the front-end when something happens.
Note that GQL eco-system (example: apollo-client, graphql-code-generator..) uses this distinction between the 2 concepts, and making the distinction helps to leverage the eco-system.
Use live queries as event subscription can lead to pitfalls
If one really wants to implement an event subscription with reactive-graphql
, as a workaround one can use a regular reactive query:
type Query {
postAdded: PostAddedEvent!
}
type PostAddedEvent {
postId: Int!
}
But this can lead to emitting much more events than expected if the Post
is changing live:
type Query {
postAdded: PostAddedEvent!
}
type PostAddedEvent {
post: Post!
}
I think you are right and I would assume it's a doable change. We need to implement the Subscription interface, there should be tests in graphql-js that we can borrow to make sure we are spec compliant