I have a nodejs express app that serves as a proxy between a client application and a graphql api. The graphql api implements the graphql-multipart-request-spec. I am using the graphql-request package to query it. The proxy application uses nestjs and multer for the upload.
According to graphql-request docs you can upload files like this
const UploadUserAvatar = gql`
mutation uploadUserAvatar($userId: Int!, $file: Upload!) {
updateUser(id: $userId, input: { avatar: $file })
}
`
request('/api/graphql', UploadUserAvatar, {
userId: 1,
file: createReadStream('./avatar.img'),
})
But that implies that the uploaded file has been saved to the file system. Is it possible to do the same thing using the buffer of the file?
I tried to turn the buffer to a ReadableStream like this:
const readable = new Readable()
readable._read = () => {} // _read is required but you can noop it
readable.push(file.buffer)
readable.push(null)
await request('/api/graphql', UploadUserAvatar, {
userId: 1,
file: readable,
})
But the graphql api returns the following error:
Unexpected end of multipart data