graphql-request
graphql-request copied to clipboard
Error when run GraphQLClient in parallel
Reproduce
My query function
try {
const client = new GraphQLClient(url, { headers: {} })
const response = await client.request(query)
do_some_thing_that_may_take_time(JSON.stringify(response))
} catch(e) {
console.log(e)
}
When I used this function to query my graphql server in sequential, it worked well. But when I applied this function into parallel scenario, on large query (large data, take long time 1s++) cases it failed at least 90%. The error log is as below:
Error: context canceled: {"response":{"errors":[{"message":"context canceled","path"
...
,"status":200}
at GraphQLClient.<anonymous> (...\node_modules\graphql-request\src\index.ts:101:13)
at step (...\node_modules\graphql-request\dist\index.js:63:23)
at Object.next (...\node_modules\graphql-request\dist\index.js:44:53)
at fulfilled (...\node_modules\graphql-request\dist\index.js:35:58)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
So I have to run it sequential before knowing what really happen. Do you have any ideas about this problem?
This might happen not because of the package, but because of the specific limitation of environments. For example, a server can block a request from a certain IP when it exceeds a threshold. For another example, your local environment might have a limit on such tasks. Would you collect more information?