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.

Apollo Client sends duplicate requests

See original GitHub issue

Intended outcome: I am trying to log response times in my Express server.

Right now, while I’m debugging, my code looks like this.

app.use(
  responseTime((req: express.Request, res, time) => {
    if (req.method === "OPTIONS") {
      return;
    }
    console.log(
      `response time (seconds) for ${req.get("origin")} ${req.method} ${
        req.originalUrl
      } ${req.body?.operationName}`,
      req.headers,
      time / 1000
    );
  })
);

Actual outcome: For every GraphQL query, I see logs for two requests.

I know these are being sent by Apollo Client because I added a dummy header (foo).

Here are a couple of example logs that occur when I refresh a page.

response time (seconds) for undefined POST /graphql MyQueryName {
  accept: '*/*',
  'content-type': 'application/json',
  foo: 'client',
  'content-length': '547',
  'user-agent': 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)',
  'accept-encoding': 'gzip,deflate',
  connection: 'close',
  host: 'localhost:4000'
} 0.0009104899999999999
response time (seconds) for http://localhost:3000 POST /graphql MyQueryName {
  host: 'localhost:4000',
  connection: 'keep-alive',
  'content-length': '547',
  pragma: 'no-cache',
  'cache-control': 'no-cache',
  accept: '*/*',
  foo: 'client',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36',
  'content-type': 'application/json',
  origin: 'http://localhost:3000',
  'sec-fetch-site': 'same-site',
  'sec-fetch-mode': 'cors',
  'sec-fetch-dest': 'empty',
  referer: 'http://localhost:3000/',
  'accept-encoding': 'gzip, deflate, br',
  'accept-language': 'en-US,en;q=0.9',
  cookie: '...'
} 0.007458307999999999

On the client side, I’m using createUploadLink. Using createHttpLink doesn’t fix it.

How to reproduce the issue: Slightly cumbersome to repro because you need client + server code. I can add this later if needed,

Versions

System:
  OS: macOS 10.15.2
Binaries:
  Node: 12.18.2 - /usr/local/bin/node
  Yarn: 1.22.4 - /usr/local/bin/yarn
  npm: 6.14.5 - /usr/local/bin/npm
Browsers:
  Chrome: 88.0.4324.182
  Firefox: 79.0
  Safari: 13.0.4
npmPackages:
  @apollo/client: ^3.3.5 => 3.3.5
  apollo-upload-client: ^14.1.3 => 14.1.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
john1625bcommented, Jun 9, 2022

This recently closed issue might help to explain why we expect the duplicate calls.

@jcreighton Hi, sorry but I can’t understand what that linked issue is trying to say. Could you explain it simply why apollo does 2 duplicate network requests by default when using network-only

0reactions
jcreightoncommented, Mar 11, 2021

Closing this as we don’t have enough information to take action. If it’s still an issue and you can provide a reproduction, I’ll be happy to re-open the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deal with optimistic responses and multiple requests?
Hey there, in our ecommerce project, we are using a lot of ± quantity inputs, which utilize optimistic responses. We observed that when...
Read more >
Operation request format - Apollo GraphQL Docs
How to send requests to Apollo Server over HTTP. ... an operationName (clarifying which query to run if the request contains multiple possible...
Read more >
Advanced HTTP networking - Apollo GraphQL Docs
The Apollo Link library gives you fine-grained control of HTTP requests that are sent by Apollo Client. You can also use it to...
Read more >
Improving performance in Apollo Client - Apollo GraphQL Docs
In some cases, a query might request data that's already present in the Apollo Client cache thanks to a different query that already...
Read more >
Advanced topics on caching in Apollo Client
Advanced topics on caching in Apollo Client ... don't check the cache for data before sending a request to your server. ... onResetStore...
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