Description
GraphQL schema doesn't convey full information about data interdependencies and relations. So it is possible to have some pieces of data stale with delta sync. Quick example:
type Category {
title: String
totalCommentCount: Int
}
type Post {
category: Category
commentCount: Int
comments: [Comment]
}
Say some comment is deleted and we are notified about it via a DELETE
event. Three things are stale now:
- Reference to this comment in
Post.comments
field Post.commentCount
field is also stale as it has to be decremented on comment deleteCategory.totalCommentCount
- same
When this happens there should be a way to update specific fields of related nodes. So in addition to UPDATE
and DELETE
events (targeting individual nodes), we need UPDATE_FIELDS
event that can notify us about specific node fields that had changed.
This event would generate dynamic new NODE_
query that will only fetch the mentioned fields and update the node. So it will look something like this:
{
eventName: "UPDATE_FIELDS",
remoteTypeName: "Post",
remoteId: { __typename: "Post", id: "1" },
fields: ["commentCount", "comments"]
},
{
eventName: "UPDATE_FIELDS",
remoteTypeName: "Category",
remoteId: { __typename: "Category", id: "1" },
fields: ["totalCommentCount"]
},
Additionally maybe allow fields
to be a fragment, i.e.:
{
eventName: "UPDATE_FIELDS",
remoteTypeName: "Post",
remoteId: { __typename: "Post", id: "1" },
fields: `fragment ChangedFields on Post { commentCount, comments { __typename } }`
},
Technically we can update related nodes fully. But that can be pretty heavy in some cases, so more targeted updates can be useful in performance-sensitive scenarios.