Skip to content
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

Stale data invalidation with delta syncing #18

Open
vladar opened this issue Oct 9, 2020 · 0 comments
Open

Stale data invalidation with delta syncing #18

vladar opened this issue Oct 9, 2020 · 0 comments

Comments

@vladar
Copy link
Contributor

vladar commented Oct 9, 2020

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:

  1. Reference to this comment in Post.comments field
  2. Post.commentCount field is also stale as it has to be decremented on comment delete
  3. Category.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant