-
Notifications
You must be signed in to change notification settings - Fork 746
Implement @fieldPolicy directive #3534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This use case will be supported by the implementation of the Thanks so much for giving me a clearer understanding of what you're looking for. |
Reading https://www.apollographql.com/docs/ios/caching/introduction I don't understand why it says "The favoriteBook field can now be queried for its title and yearPublished in a new query, and the normalized cache could return a response from the local cache immediately without needed to send the query to the server." without mentioning the @fieldPolicy directive. I'm really confused since this sentence directly confirms that a new query (FavoriteBookTitleAndYear) can be satisfied entirely from the cache (the merged data), avoiding a network request. This is the exact scenario I'm asking about - different queries using the same cached data and avoiding network requests. It's possible that @fieldPolicy is intended for a more advanced or different aspect of cache control? Are we talking about two different use cases? |
The way it's described in the docs works only if we already know that the server has returned an object in the past for the field with that id. The issue is that when resolving the The Effectively this directive gives you a way to tell the cache what the server-side behavior of that field resolver is. |
Thanks @AnthonyMDev for the explanation! Now, If I have a Mutable Fragment Definition, use it in multiple queries, and use ReadWriteTransaction.updateObject(ofType:withKey:variables:_:) to write data for a mutable fragment, could you clarify the current capabilities and limitations of this operation? Will it update cache for some queries, just previous queries that have used the same variable? If we do this and write data for a mutable fragment, we still need to write local cache mutations to the cache or not? is it just doing one or the other? sorry but I'm a bit confused 😵💫 |
It will update the fields on that object in the cache. Say you call Any field on another object that has been previously fetched and returned a So your cache could have a set of records like this:
If you still have questions, check out this article. It does a great job of explaining the underlying concepts of how the normalized cache works. |
Summary
Summary
I have a very simple use case that doesn't seem to be handled by the normalised cache properly.
I have a query that returns a list of launches:
I then have a second query that queries for a specific launch:
The data returned for the first query populates the cache, but is not used for the second query.
I have set up custom cache keys in the SchemaConfiguration.swift:
But Apollo seems to only correctly return cached data for the same query, despite the 2 pieces of data in the cache having the same cache key. This is unexpected. I get his log:
I was under the impression that If I assign an id and same uniqueKeyGroup these would work?
Version
1.18.0
Steps to reproduce the behavior
Minimal test case: https://github.com/comontes/ApolloiOSBug1
Logs
Anything else?
No response
The text was updated successfully, but these errors were encountered: