I have a query that returns the sample data below
{
__typename: 'Typehere',
name: 'type',
address: 'address type'
}
When I use useQuery
with an option of fetchPolicy: 'cache-first' the GQL API returns the correct data. But when I use console.log(response), the data will now transform to
{
__typename: 'Typehere'
}
Api call and response for fetchPolicy: 'cache-first'
console.log(response)
Why is this happening?
I tried fetching the data using fetchPolicy: 'no-cache' and works without issues, however, I need to cache it for optimization. I've also tried other fetch policies stated in the apollo client docs.
Solved it using possibleTypes
const cache = new InMemoryCache({
typePolicies: {....}
possibleTypes: {
Typehere: ['Type1', 'Type2']
}
});
Turns out that apollo client needs to know possible implementations of Typehere