Ideas for making LiveQueryStore more powerful
#14 opened on Aug 19, 2020
Repository metrics
- Stars
- (439 stars)
- PR merge metrics
- (Avg merge 1d 12h) (3 merged PRs in 30d)
Description
The approach of calling liveQueryStore.triggerUpdate("Query.users") might not scale that well. It could return different results for different users. It does not address the unique field argument combinations.
Resource-Based Updates
If a user with id fgahex changes we ideally only want to update queries that select the given user.
Object types that have an id field could be automatically collected during query execution (and updated during re-execution).
Query
query user @live {
me {
__typename
id
login
}
}
Execution result:
{
"data": {
"__typename": "User",
"id": "fgahex",
"login": "testuser"
}
}
Will result in the following entry for the selected resources of that query: User.fgahex.
An update for all the live queries that select the given user could be scheduled via liveQueryStore.triggerUpdate("User.fgahex").
Things to figure out:
What is the best way of collecting resources?
This would require sth. like a middleware for each resolver that gathers the ids and attaches them to the result (as extensions?) that the liveQueryStore can pick up (maybe this?).
Another solution would be to push this to the user so he has to register it manually, by calling some function that is passed along the context object?
The information could also be extracted from the query response. However, that would have the implications that it needs at least the id extracted for each record (or even id + __typename for GraphQL servers that do not expose unique ids across object types). Since most client-side frameworks encourage using unique ids for identifying Objects anyways that shouldn't be that big of a limitation. An additional drawback would be that the whole result tree must be traversed.
Pros:
- The server automatically keeps track of the resources a query selects.
- Does work for resources that got replaced with objects of another id (by calling
triggerUpdatefor the previous resource).
Cons:
- Big queries result in a lot of strings that are stored additionally in memory
- Does only work for object types that have an
idproperty. - Does probably not play that well with a list type.
- Does not solve the field argument issue.