New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File upload receiving buffer instead of promise with createTestClient #2372
Comments
I'm also receiving |
No, I had to leave it out until this is fixed |
It feels a little hacky, but I got this to work by doing the following: import { createReadStream } from 'fs';
const fileName = `${__dirname}/...`;
const response = await mutate({
mutation: UPLOAD_PRODUCT_IMAGE,
variables: {
file: {
createReadStream: () => createReadStream(fileName),
filename: 'image.jpg',
mimetype: 'image/jpeg',
},
},
}); Instead of using |
@joemckie does this still works for you? I am getting the following error:
Any ideas? |
@loremaps I think I removed this code in a refactor when I moved to NestJS unfortunately so I wouldn't be able to test it out any more 😞 FWIW, I remember this being an issue during the refactor, and I found it was easier to test it by using |
@loremaps I am getting the same error as you, did you find a solution? EDIT: Okay, so digging into it I found graphql-upload expects to receive an instance of the Upload class. I got around it with ...
|
We are removing the built-in
|
The solution of @Nabrok still works. Even when using It's also possible to make testing easier by not using a real file. Simply create a variable and a Readable from an iterable and pass it to import { Readable } from 'stream'
import Upload from 'graphql-upload/Upload.mjs'
const file = new Upload()
file.promise = Promise.resolve({
createReadStream: () => Readable.from(['Content']),
filename: 'file.txt',
mimetype: 'text/plain',
})
server.executeOperation(
{
query: QUERY,
variables: { file },
},
) |
Tried the solutions commented on this thread but still no luck,
|
Calling a resolver using createTestClient and a file gives a buffer instead of a promise like you would normally receiving from a client.
Is the Upload scalar supported by createTestClient?
The text was updated successfully, but these errors were encountered: