Hi there! I’m facing a practical issue in the usage of GraphQL + Apollo Client. Let’s assume we have a type Person that is being queried on different pages of an application (simplified example):
fragment BasicUser on User {
firstname
lastname
}
query UsersForOverview {
users {
...BasicUser
}
}
fragment EmailUser on User {
firstname
lastname
email
}
query UsersForAddressBook {
users {
...EmailUser
}
}
Now, when querying UsersForOverview
first, Apollo Clients InMemoryCache is being populated. Cache normalization kicks in so I’ll have a number of cache key entries like e.g. User:1234
and User:2345
. Afterwards, when running the UsersForAddressBook
query the result will be delivered from the cache. Technically, this seems intended behaviour (given how cache normalization works). From a functional perspective though, I’d clearly expect a cache miss, given that not all requested data is present in the cache.
Two questions arise:
- Is my understanding correct that the cache works as intended?
- Is there a way to make Apollo Clients cache return a cache miss if not all requested fields are present?
If my understanding is correct and there is no way to make this work, this would IMO make the usage of fragments to only retrieve needed data impossible :/, so therefore I hope I’m just not getting a detail here :).
Any help would be greatly appreciated!
Cheers, Daniel