Skip to content
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

Error: file is missing, Promise has not been resolved (sometimes) #225

Closed
adrienharnay opened this issue Nov 18, 2020 · 7 comments
Closed

Comments

@adrienharnay
Copy link

Hello,

Since upgrading from 8.0.2 to 11.0.0 (node 14), when uploading a file from iOS (tested on Safari, Chrome) or MacOS (tested on Safari, Chrome DOESN'T HAVE the bug), the file is sometimes missing as the Promise has not been resolved with its content.

I have now tested around 100 times on Chrome MacOS (100 worked), and around 100 times on Safari MacOS, Chrome iOS and Safari iOS (around 40 worked). When it did not work, the file is missing and only the promise and resolve keys are here.

I would gladly help you fix it if I can, would you have any idea where it may come from?

@jaydenseric
Copy link
Owner

Thanks for the report, although I'm not really sure what could be wrong.

Could you please explain in as much detail as you can what happens in the times the upload doesn't work? You say the Upload scalar promise doesn’t resolve, does it just sit there forever, is there an eventual timeout and error?

Also, do you think this upstream issue with busboy and Node.js v14 events could be somehow related: mscdex/busboy#237 .

@adrienharnay
Copy link
Author

Hey, sorry about the delay. It seems doing await image.promise does the trick and generates image.file (note: await file doesn't work).

About your questions: I'm integrating a back-end which is using graphql-upload and don't have all the info, but it seemed like the promise didn't resolve (again, on the browsers which I mentioned, and not everytime - testing 10 times would guarantee I got the error at least once though).

I don't have any idea about the busboy issue, sorry.

Please let me know if I can provide more info, or if this is just intended behavior.

@jaydenseric
Copy link
Owner

It seems doing await image.promise does the trick and generates image.file (note: await file doesn't work).

This is confusing to read, because you should not be accessing a .promise or .file on the Upload scalar promise in the resolver. Here is the right way:

const { filename, mimetype, createReadStream } = await image;
const stream = createReadStream(); // Promisify this, and await it to complete.

If you run npm ls graphql-upload, what version is installed, and are there multiple?

Perhaps you are using an old version (perhaps even multiple version are installed), and maybe also using the API incorrectly in resolvers.

@shrodingers
Copy link

Hello, I'm one of the back-end developper that worked on the topic.
We are currently using the version 11.0.0.
We were using the syntax you suggest on node 12.xx, but since upgrading to node 14, we had to bump the version of graphql-upload as a dependency of apollo-server (as per this comment, so we upgraded to version 11.0.0, and the syntax you propose don't work anymore for us.
The object we have is a direct Upload object, instead of FileUpload, and has this shape: {resolve: ƒ, reject: ƒ, promise: Promise, file: {…}}, with file being a FileUpload object. So we had to access the underlying file property in order to have access to { filename, mimetype, createReadStream }.
This worked in most of the cases, but we had to also await the underlying promise in order to be sure our file property is populated. Seems like if there was a step bypassed in the object construction in order to have a proper FileUpload object in the end.
In the end, finally found the source of the issue, but can still be interesting for further investigation :
After multiple tests, it appears this syntax works fine with graphql-upload version 9.0.0 but with version 11.0.0 there is an issue with the way apollo-server handles the upload, and we have access to a primitive Upload object instead of the final FileUpload one.

@jaydenseric
Copy link
Owner

Apollo not updating their dependencies for years at time is giving everyone huge headaches! Several major Node.js versions have come out while Apollo Server has been stuck at v2 :(

Please double check you have fully disabled and replaced the outdated Apollo Server graphql-upload implementation; if the documented APIs for the current graphql-upload version are not working they way they are supposed to that is a problem in your codebase that needs to be investigated and fixed. Possibly you are using middleware from one version, and the GraphQLUpload scalar from another.

You can see a working example of Apollo Server and Koa here:

https://github.com/jaydenseric/apollo-upload-examples/tree/master/api

Best of luck with the investigation, let us know how it goes :)

@st33fn
Copy link

st33fn commented Jun 1, 2021

Hello, just to report I have the same problem as @adrienharnay and @shrodingers, meaning i get the same Upload object of exact shape as @shrodingers suggested. graphql-upload 12.0.0, node 14.15.4, apollo-server-express 2.25.0. await file doesn't work as well.

another edit (dev dependencies):

"apollo-server-express": "^2.25.0",
"apollo-upload-client": "^15.0.0",
"express": "^4.17.1",
"graphql": "^15.5.0",
"graphql-upload": "^12.0.0",
"svelte-apollo": "^0.4.0"

@programmer4nd
Copy link

programmer4nd commented Jun 19, 2023

as @adrienharnay described, same issue for me on node 16,
uploading file is not working in almost every 3rd rquest on safari browser.
"graphql-upload": "^13.0.0",
"@apollo/server": "^4.4.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants