queryDeduplication not working as expected in apollo-client@2.0
See original GitHub issueIntended outcome:
The same graphQL query (same variables and query string), executed by different components on load of the app, should only result in one network request (visible in the network tab). Before upgrading to apollo-client 2.0, we would experience such behavior.
Actual outcome:
Now that we have upgraded to apollo-client 2.0 we see a network request for every time we execute a query.
The following code is what we have implemented using apollo-client 2.0 and shows 2 network requests in the network tab. Please note that we are not mentioning queryDeduplication
since it is supposed to be set to true
by default:
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createHttpLink } from 'apollo-link-http';
import QUERY from 'gql/queries/query.js';
const client = new ApolloClient({
cache: new InMemoryCache(),
link: createHttpLink({ uri: '/graphql' })
});
client.watchQuery({
// I've tried every fetch-policy except "cache-only"
// just to see if any would actually dedup requests
fetchPolicy: 'cache-and-network',
query: QUERY,
variables: { id: 'abcd' }
}).subscribe({
error: error => {
throw new Error (error);
}
});
client.watchQuery({
fetchPolicy: 'cache-and-network',
query: QUERY,
variables: { id: 'abcd' }
}).subscribe({
error: error => {
throw new Error (error);
}
});
Version
- apollo-client@2.0.1
- apollo-cache@1.0.0
- apollo-cache-inmemory@1.0.0
- apollo-link-http@1.0.0
- graphql@0.11.7
- graphql-tag@2.4.2
Thanks for your help!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Vue-apollo subscriptions not working as expected
I am working on vue-apollo and was able to use mutations and queries, but am facing issue using subscriptions. The apollo-express server ...
Read more >class ApolloClient - Apollo GraphQL Docs
A custom version that identifies the current version of this particular client (e.g., 1.2 ). Apollo Server and Apollo Studio use this property...
Read more >Pitfalls I fell into during Apollo Client 3.0 migration
Recently I worked on migrating Apollo Client to 3.0 from 2.6 in our project. ... with an error message saying TypeError:(0, _client.gql) is...
Read more >Handling GraphQL errors like a champ with unions and ...
When I started using GraphQL, I had some issues with changing the mindset ... How would I distinguish a “user does not exist”...
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 Free
Top 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
@manbropig @Wenzil @malexandre this is first up on my bug squashing adventure this week!
Sorry for the delay, after the 2.0 launch + new sites + graphqlsummit, we took a week off at our company for a company wide hack week. I’m back on Apollo this week and am making a few milestones to work through. This is priority number one for me
The new dedup link will be part of the next release!