apollographql / apollographql/datasource-rest
"An unexpected error occurred" in didEncounterError while executing a graphql query
- Dominant language
- TypeScript
- Stars
- 48
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
While migrating from apollo-server v3 to v4 getting error while executing few graphql queries, whereas it's working fine for other graphql queries
```
SOME_GRAPHQL_QUERY TypeError: The "list" argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView.
at TextDecoder.decode (node:internal/encoding:443:16)
at Qe.someApplicationFunction1 (path/build/server.js:1:130571)
at Qe.didEncounterError (path/build/server.js:1:133550)
at path/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:236:26
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Qe.fetch (path/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:269:21)
at async Qe.post (path/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:127:17)
at async Qe.t.timeout (path/build/server.js:1:135424) {
code: 'ERR_INVALID_ARG_TYPE'
}
```
The _**error.extensions.response.body**_ received in didEncounterError is:
```
{
message: 'An unexpected error occurred',
request_id: '59ba9f0ad155044a5f9d983891ab9559'
}
```
Upon analysing the issue from the error callstack, found that the error is originating from ```const parsedBody = await this.parseBody(response);``` inside performRequest method.
Inside parsedBody, these are values found in response:
```
contentType: application/json; charset=utf-8
contentLength: 97
response.status: 500
```
As the graphql server working fine for other queries, I suspect there might be some issue in the schema of few queries for which it fails with the above error message. So I tried running the query by passing just one String type input but it still failed with same error.
Any assistance on this would be highly appreciated
Versions used:
node: v20.17.0
graphql: ^16.9.0
@apollo/datasource-rest: ^6.3.0
@apollo/server: ^4.11.2
graphql-tag: ^2.12.6
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with performRequest and parseBody in @apollo/datasource-rest, then trace the didEncounterError call using the listed Node, GraphQL, Apollo Server, and RESTDataSource versions. Reproduce a failing query and compare its response handling with a working query; done means the failing request no longer raises the TextDecoder TypeError and exposes the intended response or error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100