Hacker News new | past | comments | ask | show | jobs | submit login
Apollo Client – Demystifying Cache Normalization (apollographql.com)
32 points by lucasandrade 3 days ago | hide | past | favorite | 4 comments





One thing I want to call out, and seems to be the case (based on my understanding of the client code?), Apollo client doesn't try to understand the query and make intelligent use of the normalized cache based on the actual query going to be made. For example:

  query profile(name: $name) {
    id, name, address
  }

  query profile(id: $id) {
    name, address
  }
If the second query never made before the first query, even if they access the same object, it needs to make the network call again for the second query.

However, once you made all the queries, the normalization process will make sure the object is always fresh and there is no need for the extra network trip.


I have observed this same thing and found it unintuitive, but I think it makes sense? technically your `profile` field could be returning anything (even though you're passing an `id` param in, you potentially could be doing something like returning a sibling profile for the given id). iirc, there is a thing called "cache redirects" that let you teach apollo the right thing to do here.


Ha, thanks! I mostly use Apollo iOS and didn't notice this, will check it out!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: