Any best practices on naming queries and fragments and query reuse? #1495
-
Hi there! Is there a guide on how to reuse queries correctly and what's a good idea and what's not? Also how you approach the naming of queries and mutations and how do you use fragments maybe? :) Currently, I try to use fragments to build a query up from the consumer components up to the place where it's getting fetched to avoid overfetching. Something similar to what Relay does by design AFAIK. Is it a good approach? And a bit of how Graphcache works: Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
When you use the normalized cache and your fields are in the cache it should be a hit, sometimes the cache will need some additional information. Like when you have a list-view and you go to the detail-view of one of the items, you can solve this with So generally if the schema tells us a field is nullable and missing --> we'll fetch it and mark your query as stale When the root field doesn't know the connection, for instance Query.todos vs Query.todo(id: x) we can use the cache.resolve technique. |
Beta Was this translation helpful? Give feedback.
When you use the normalized cache and your fields are in the cache it should be a hit, sometimes the cache will need some additional information. Like when you have a list-view and you go to the detail-view of one of the items, you can solve this with
cache.resolve
as documented here.So generally if the schema tells us a field is nullable and missing --> we'll fetch it and mark your query as stale
If the fields are in cache for the given query we'll give you the information
When the root field doesn't know the connection, for instance Query.todos vs Query.todo(id: x) we can use the cache.resolve technique.