You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our app we have cache redirects for fields using typePolicies and toReference. Since version 3.4.8 the values the cache returns for these fields has changed during loading or if the reference is not found. The issue happens only when we use a query with fetchPolicy set to cache-only.
Intended outcome:
The data from the userQuery hook should return undefined during loading or if the reference cannot be found.
Actual outcome:
The data from the userQuery hook returns and empty object {} during loading or if the reference cannot be found.
@Antarases A possible workaround: In our app, adding an if statement inside the type policy read function to check if the reference has an id field solved the issue.
For example:
typePolicies: {Query: {fields: {user(existingData,{ args, toReference, readField }){// Search and return data if it already exists.// https://www.apollographql.com/docs/react/caching/advanced-topics/#cache-redirects-using-field-policy-read-functionsconstreference=toReference({__typename: 'User',id: args?.id});// Check if reference is not empty (regression from Apollo client since 3.4.8)constreferenceData=reference&&readField('id',reference) ? reference : undefined;returnexistingData||referenceData;}}}}
Hello! 👋
In our app we have cache redirects for fields using
typePolicies
andtoReference
. Since version 3.4.8 the values the cache returns for these fields has changed during loading or if the reference is not found. The issue happens only when we use a query withfetchPolicy
set tocache-only
.Intended outcome:
The
data
from theuserQuery
hook should returnundefined
during loading or if the reference cannot be found.Actual outcome:
The
data
from theuserQuery
hook returns and empty object{}
during loading or if the reference cannot be found.How to reproduce the issue:
I've recreated the issue on CodeSandbox:
https://codesandbox.io/s/eager-mahavira-ie04m?file=/src/index.jsx
I've modified your template by:
Pet
typepets
field to thePerson
typeALL_PEOPLE
query to includepets
SINGLE_PET
query that allows you to get aPet
item by idSINGLE_PET
query with thefetchPolicy
set tocache-only
pet
usingtypePolicies
andtoReference
Versions
3.4.8 and newer
Similar closed issue
#6368
Is this an intentional change or a regression?
Thank you for all the amazing work you've done with Apollo!
Žiga
The text was updated successfully, but these errors were encountered: