question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

queryDeduplication not working as expected in apollo-client@2.0

See original GitHub issue

Intended 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jbaxleyiiicommented, Nov 13, 2017

@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

1reaction
jbaxleyiiicommented, Nov 16, 2017

The new dedup link will be part of the next release!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found