Slide 123
Slide 123 text
story {
can_viewer_like,
does_viewer_like,
likers {
count
},
comments {
...
}
}
story {
can_viewer_like,
does_viewer_like,
likers {
count
},
comments {
...
}
}
story {
does_viewer_like,
like_sentence,
likers,
}
story {
does_viewer_like,
like_sentence,
likers,
}
what can change what we’ve stored
∩
Instead, we put the logic to determine the correct mutation query into Relay itself. How does this work? Well, intrinsic to each
GraphQL mutation is the set of data that *can* change when we perform that mutation. This is independent of what any client
renders; it's a property of the mutation itself. Here is the set of things that can change when a story_like occurs.
If we always queried for everything that *could* change every time we did a mutation, we would certainly end up with a
consistent state on the client since we would have updated anything that could possibly change, but we could also potentially
be fetching a lot of data that we don't need, which is wasteful.
So we have Relay keep track for each ID in its store of what set of data the client has retrieved for that ID and put into its store.
Here's the set of data that we might have fetched and stored for my story.
To build the mutation query, Relay intersects this set of things that *can* possibly change with what we actually have in the store.
This ensures that we query for exactly the set of fields that needs to be updated. In this case, we end up with this query.