Closed cspecter closed 2 years ago
What is your client configuration?
Just added the relevant setup code.
The problem is that you're changing the arguments so the cache have no idea of which product to fetch from the cache, so it needs to go to the network. You can solve this by writing to the cache with cache access methods defined in the readme.
OK, thanks. We will look into that.
Our GraphQL server uses a relay style system. We have a setup like this for a table of products. We have one view in our app where it shows a list (feed) of products and one view that shows a product detail. Functionally these pull in the same data. Our app hits the feed view first, then the user can click on a product to get a detail. The setup looks like this:
This returns data that looks like this in both cases:
In the first case, for the
GetProducts
query we are asking for things that are past a certain data with the ability to pass in cursors. In the second case, for theGetProductBySlug
, we want just a single product referenced by it's slug.After loading the
GetProducts
list, I see the data for the individual product is stored in the cacheProduct:2c749d82-d6d3-4f8e-a281-4b9afe5465b4
. When we go to the next page and run theGetProductBySlug
query, it always hit the network first, even if the data for the product it wants is in the cache and the policy is set toFetchPolicy.cacheFirst
. We want to grab the individual product by it's slug in order to have a friendly deep link.If we set the cache policy to
FetchPolicy.cacheOnly
we get this errorCacheMissException(Could not resolve the given request against the cache.
I see in the cache that there is a Query key with the following:
My assumption is that I can query the cache like our server, but I guess this is not the case. After it hits the server for the
GetProductBySlug
query, I see this has been added to the Query key in the cache:Once that is in there it will pull from the cache properly.
In our React web app using Apollo, making this kind of query is definitely pulling from the cache. Do I need some sort of custom Resolver here? Or to set the queries up another way?
Here is how our app is configured: