-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Feature Request: Event-based subscriptions #2317
Comments
Here is a cleaner workaround to have event-based subscription, though it needs another graphql server instance to expose the subscription API. |
@heyrict One of the biggest challenges/decisions with event based subscriptions is how does the client recover from loss of events? Does the server store what events are delivered to clients? This involves maintaining state at the server (using something like a message queue maybe?) and becomes even more complicated when you bring in horizontal scalability of the subscriptions server. We support live queries because they are easy to reason about, very expressive, extremely performant and the server need not store any state (in our implementation). |
@0x777 Well, I like hasura's performant design and don't think bundling another layer inside to maintain state is a good choice. |
One thing I've found is, it is very hard to write a mutation that would optimistically update a subscription with apollo, or maybe even impossible, since apollo doesn't seem to have build in mechanisms to automatically update subscriptions (using optimisticResponse) and there is no possibility to read/write subscriptions from/to cache. This must be due to the fact that, as @heyrict states, most implementations and even apollo docs use event based subscriptions instead of live queries. Would love to see some workaround for live-queries + optimistic response, I couldn't manage to get this combination to work with apollo. |
@bkniffler I am not sure if I have understand If you are using <Subscription subscription={SOME_LIVE_QUERY}>
{this.renderLiveQuery}
</Subscription> Then the subsciption data will always reflect what If you want to use optimistic response to update the live query, you should store query data in local cache with a <Query query={INITIAL_QUERY}>
{params => <QueryRenderer {...params} />}
</Query> class QueryRenderer extends Component {
componentDidMount() {
this.unsubscribe = this.props.subscribeToMore({
query: SOME_LIVE_QUERY,
update: (...) => {/* Logic to update cache here */},
...
});
}
...
} |
I believe if hasura add support to redis, this feature will be possible.@0x777 |
What has this with Redis? |
The problem with live queries is that they always deliver all the information. Say I have a table with 10'000 records. One of them changes. If event based subscriptions existed, the client could:
This seems so obvious I am sure I must have missed something essential. What have I missed? |
I posted what might be a slightly simpler work-around for some scenarios here: apollographql/apollo-client#5267 |
Any updates on this? |
hi guys, any updates on this? would be amazing to have the ability to receive the initial data + only the changed data in future updates. |
@marcusrohden What you want is probably looking at the streaming API: https://www.youtube.com/watch?v=C1TDDlXPSmI |
Any updates? |
Also wondering if this has been explored anymore! |
Reopen of #1355 .
To inspect whether it is good to use event-based subscriptions or live queries, I've gone through many articles and found this comment best describes the current state of live queries and event-based subscriptions.
There are still use cases of event-based subscriptions, especially when performance count more than reliability (take an example of twitter like subscription)
Another thing is that, most subscriptions in the current graphql ecosystem use event-based ones. It will be hacky to convert an existing project with subscriptions to hasura.
The hacky part of using live query for event-based subscriptions is that
update
orcreate
events need extra effort (adding updated_at columns to sort with, etc.)cc: @coco98
The text was updated successfully, but these errors were encountered: