apollographql / apollographql/datasource-rest

Post method is not able to properly download a Stream

Open
#356 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
48
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Hi I'm not sure if this is an issue or I'm doing something wrong.
I'm trying to call an external API to download a PDF file that I will later encode into a base64 string.

I used .post from RESTDataSource class.
But the string I receive is not correct.

I tried the same using axios and everything is perfectly working.
This is the working code:

```
const response = await axios({
method: "post",
url: `${this.baseURL}/storefrontapi/hot/orders/${orderId}/export/pdf`,
headers: {
Accept: "application/json-patch+json, */*",
authorization: `Bearer ${this.context.token}`,
"Content-Type": "application/pdf",
},
responseType: "arraybuffer", // Ensure binary data is handled correctly
})
```

This is the not working call using RESTDataSource method.

```
const response = await this.post(`storefrontapi/hot/orders/${orderId}/export/pdf`, {
headers: {
Accept: "application/json-patch+json, */*",
authorization: `Bearer ${this.context.token}`,
"Content-Type": "application/pdf",
},
})
```

I can't use responseType here because is not supported, I didn't find any way to pass it to the post function.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the RESTDataSource.post entry point and its response handling for binary data; the issue provides no file or test path. The work is done when a POST can preserve the downloaded PDF bytes and support the needed response configuration, with a regression test covering the stream response.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.