Closed SamuelNoB closed 2 years ago
Without looking in detail at the code you are sharing, generally when there are errors about an abort or disconnect it can be because you are not correctly promisifying and awaiting the individual file uploads in your GraphQL API resolvers. As per the Tips section of the readme:
Promisify and await file upload streams in resolvers or the server will send a response to the client before uploads are complete, causing a disconnect. — https://github.com/jaydenseric/graphql-upload#tips
Here is an example of promisifying the upload's read stream:
Without looking in detail at the code you are sharing, generally when there are errors about an abort or disconnect it can be because you are not correctly promisifying and awaiting the individual file uploads in your GraphQL API resolvers. As per the Tips section of the readme:
Promisify and await file upload streams in resolvers or the server will send a response to the client before uploads are complete, causing a disconnect. — https://github.com/jaydenseric/graphql-upload#tips
Here is an example of promisifying the upload's read stream:
thanks for the answer but that's not the cause of the error. when I run the test in debug mode, I can se that my addFile
resolver doesn't even get called because none of the breakpoints are activated.
Closing because this issue is more of a request for help debugging project code than a graphql-upload
bug report or feature request, which are the only kinds of issues we keep open.
You absolutely can test file uploads (I do so in all sorts of projects), so keep at it and you'll get it going with your chosen tools eventually. I suggest keeping away from bloated testing frameworks like jest
and supertest
and write as close to standard JavaScript code as you can, using standard fetch
, FormData
and File
/Blob
APIs. The code will be a lot less mysterious and maintainable, and you will understand better how the systems being tested actually work in production.
Good luck!
This repo seems to have a lot of answers that can be boiled down to "if you keep trying, you can figure it out," leading to the issue getting closed. This shouldn't be closed — there's no easy way to test this library when using apollo-server-express
. A working example piece of code would be great.
Hi, I was trying to create a
jest
test withsupertest
that uploads a file to the client. i've already found issue #125 that faced the similar problem, and I already tried jaydenseric and awilderink answers, but none of them worked. Bellow is my code right nowAs you can see, my
input.File
is the file that represents my Upload field.Unfortunatelly when I run the test an error is shown.
How can I implement that test correctly?