I’m trying to understand this better, but what I don’t get is when/how cache invalidation happens.
Jesse Buchanan
21

Hey Jesse,

So I think the key answer to you’re question is here:

what if you fetch some other query and realize that the author with an ID of 5 has changed his/her name

Here’s an example I hope makes sense, using the same schema as the original post.

Let’s say we make this query:

query {
author(id: "7") {
name
id
}
}

Now we have the name and id of Author 7, let’s call the Author Stephen.

Now at some other point in time, in another part of our app we make the following query:

query {
author(id: "10") {
name
id
coauthors {
name
id
}
}
}

This query returns the author with id=10, as well as author 10’s coauthors. What if one of the id’s of the coauthors is 7, and now instead of the name being Stephen it is now Sashko. Well since we just made this query the previous query is now out of date, because Author 7 has changed his name from Stephen to Sashko, so our cache will be updated, and other places in our application that refer to Author 7 will now have the new name updated in the UI.

I hope this example makes sense and answers your questions!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.