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
Thanks for your help!
@manbropig that's no good! We have tests for this but if you are seeing the issue we clearly aren't testing everything! I'll see about improving those tests, but would you be able to create a reproduction of this?
We have a template to make creating these easier
@jbaxleyiii here is the reproduction https://github.com/manbropig/react-apollo-error-template/tree/gh-pages/bug/no-query-dedup
Please let me know if you need anything else, and thanks for looking into this!
@jbaxleyiii Can you give us an ETA on when we can expect a fix?
Asking because it will factor into whether we will include the migration to v2 in our next app release
I'm also having this problem. I'm currently trying to switch to apollo-client 2 on my company main project, but I can't until this is fixed.
@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
This should be fixed via https://github.com/apollographql/apollo-link/pull/242
new version of dedup link is release as 1.0.1, I'm going to do a release of AC which removes the hard locked dependencies to make it easy to upgrade parts like this
The 1.0.1 build threw a lot of errors on AC tests, I've removed it for now and will keep this issue open until its fixed
The new dedup link will be part of the next release!
Most helpful comment
@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