Cache Exchange with React #3638
-
I'm sure this has been asked to death, so here it comes again. If I have a schema like this:
If I perform a query like so:
Then in a sub component I have this:
Is it possible in that sub component to do this: I had a read through the documentation and it looks possible, unless I've completely misunderstood it... I also tried this:
That doesn't seem to do it however. Anyway, thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The resolvers is indeed the first step to start with. In the above example however please do note that The other resolver:
The important thing to note here is that the two queries' selections won't match. And that's quite a common problem. When a field is nullable and you use Schema Awareness, it understands that some fields can be left out, just like in error cascading on the API side. This allows fields to be set to However, in your schema This is mentioned in the docs:
What I'd recommend today though, which isn't clear because we haven't updated the documentation in a while (and it does require a large restructure potentially), is that schema awareness isn't necessarily needed in for partial cache results. That's because you can also use The Do note though that since the field isn't nullable, if you're generating/deriving TypeScript types for your queries, you may want to make sure you're using a tool that understands The alternative way though, if you want to continue using Schema Awareness instead, is to make |
Beta Was this translation helpful? Give feedback.
The resolvers is indeed the first step to start with. In the above example however please do note that
classUnits
is not defined correctly in all likelihood. You've written a resolver that returns the shape of a single entity for what's likely supposed to be a list, which will probably just fail.The other resolver:
classUnit: (_, args) => ({ __typename: 'ClassUnit', id: args.id })
looks just fine.The important thing to note here is that the two queries' selections won't match. And that's quite a common problem.
There's an important two important concepts to understand here first though, nullability a…