Cache with {addTypename:false} causes query to return empty data when fragments are used
See original GitHub issueI have a simple query described in a .gql
file:
fragment thingBody on Thing {
id
name
description
}
query things {
things {
...thingBody
}
}
I have a client with this configuration:
const client = new ApolloClient ({
new InMemoryCache({ addTypename: false}),
new HttpLink({ uri: myURI}),
});
Intended outcome:
This query should return this data, which is identical to what’s returned when using the no-cache
policy:
{
things: [
{
id: '001',
name: 'Thing1',
description: 'This is a standard thing',
},
{
id: '002',
name: 'Thing2',
description: 'This is a standard thing',
},
{
id: '003',
name: 'Thing3',
description: 'This is a standard thing',
},
]
}
Actual outcome:
{ things: [ {}, {}, {} ] }
How to reproduce the issue:
Configure a cache and client as above and use any query with a fragment.
Versions
Binaries: Node: 14.6.0 - /usr/local/bin/node npm: 6.14.7 - /usr/local/bin/npm npmPackages: @apollo/client: 3.1.4 => 3.1.4
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Configuring the Apollo Client cache - Apollo GraphQL Docs
If true , the cache returns an identical ( === ) response object for every execution of the same query, as long as...
Read more >How to remove the `__typename` field from the graphql ...
I tried changing the addTypeName: false in the Apollo client in GraphQL ... fragmentMatcher.js:26 You're using fragments in your queries, ...
Read more >Configuring the Cache – Angular - GraphQL Code Generator
This article describes cache setup and configuration. To learn how to interact with cached data, see Reading and writing data to the cache....
Read more >How to fix Apollo's MockedProvider returning empty objects for ...
return ( <MockedProvider addTypename={false} mocks={MOCKS}> {children} ... For your mocked query response, add __typename to each fragment.
Read more >doc/development/fe_guide/graphql.md - GitLab
Fragments are a way to make your complex GraphQL queries more ... When the Apollo Client is used in Vuex and fetched data...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If I use the
no-cache
option or the oldapollo-fetch
module, the query “just works”. I was a little surprised that adding a cache could cause incorrect query results, I assumed it could be implemented in such a way that it did no harm. Thanks for the info, adapting to having__typename
injected into everything won’t be a major issue for me.FYI for anyone finding the same issue disabling the cache is the only solution I’ve found. See this answer and dont forget to add back in
{ addTypename: false }
to the “diasbled” InMemoryCache in order to avoid the errorIntrospection is not allowed.
from the server.Important: this seems to break our use of a paged query as below. I’ll update if I solve that issue as well
const { data, error, loading, fetchMore } = useQuery(gql(query), { variables: { term, skipCount: 0 } });