Apollo Client sends duplicate requests
See original GitHub issueIntended 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:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top 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 >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
@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
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.