How does apollo filter the normalized cache

Hi,

I’m pretty new to apollo (and graphql for that matter). If I understand correctly, due to the normalized cache apollo can give you already (possibly partial) results for queries you have not ran before but where the result set overlaps a previous query (in contrast to some other libraries which only do query result caching).

However, how does apollo which documents match the query?

As a concrete example, here’s a query in the format I use:

  query GetTags{
    tags(filter: [{ property: "label", operator: EQUAL, values: ["foo"] }]) {
      entities {
        id
        label
      }
    }
  }

In my (java) backend, these filter arguments are being translated to a where clause in a sql query.
But how can Apollo already return partial results if it doesn’t know how to interpret this filter argument?
I guess I have to implement this in the frontend somewhere or am I misunderstanding how Apollo works?

Hi! Apollo will store every permutation of a query’s variables as a separate field in the cache, so in fact it can’t return partial results in these cases. I’ve recently written a lengthy guide on Apollo’s cache and how to best handle cache manipulation - you might like to give it a read-through to gain a clearer understanding on the topic! apollo-augmented-hooks/CACHING.md at master · appmotion/apollo-augmented-hooks · GitHub

1 Like

This is exactly the kind of information I was looking for, very nice write-up!