0
What is the best practice for keeping subscriptions in sync with your query schemas?
My previous exposure to graphQL subscriptions was from Hasura, which would implement subscriptions for every table such that when a subscribing is made, the current set would be sent over the wire (followed by any updates).
const data = useSubscription(...) // Gets the latest data, every time
Now that I’m outside of Hasura, I see that that approach has an issue: it is expensive.
Instead, we should be using queries for most of the data and subscriptions only for the specific fields we want to watch.
/*
query {
posts {
id
content
upvotes
}
}
*/
const data = useQuery(...);
/*
subscription {
post {
id
upvotes
content
}
}
*/
useSubscription(...)
My issue with this is that it decouples data we show on initial from data we are "watching".
If a post
gets a new field: downvotes
, then I need to remember to add to the subscription query, or else it will not be watched.
How can I make sure I keep my query model in sync with my subscription model?
|