[HN Gopher] Apollo Client - Demystifying Cache Normalization
___________________________________________________________________
Apollo Client - Demystifying Cache Normalization
Author : lucasandrade
Score : 26 points
Date : 2021-04-07 17:37 UTC (5 hours ago)
(HTM) web link (www.apollographql.com)
(TXT) w3m dump (www.apollographql.com)
| liuliu wrote:
| 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.
| xiaomai wrote:
| 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.
| candylifter wrote:
| Yup, you do it via type policies in v3
|
| https://www.apollographql.com/docs/react/caching/advanced-
| to...
| liuliu wrote:
| Ha, thanks! I mostly use Apollo iOS and didn't notice this,
| will check it out!
| [deleted]
___________________________________________________________________
(page generated 2021-04-07 23:02 UTC)