Closed chereseeriepa closed 3 years ago
worked on this with @chereseeriepa - as she said we've got that hack in place, and uploads are working happily now.
We're not sure why it's not an instanceof Upload
, had trouble following where that instantiating is happening
It looks like the Upload
scalar JS is not setup correctly; it appears you're using:
const { Upload } = require('graphql-upload');
When it should be:
const { GraphQLUpload } = require('graphql-upload');
See:
https://github.com/jaydenseric/graphql-upload#class-graphqlupload
As a side note, it's a good idea to always use deep imports when they are available:
const GraphQLUpload = require('graphql-upload/public/GraphQLUpload.js');
This way only exactly the JS you need in a given context loads into memory, and if you ever bundle that code you won't rely on slow and unreliable "tree-shaking".
It looks like the
Upload
scalar JS is not setup correctly; it appears you're using:const { Upload } = require('graphql-upload');
When it should be:
const { GraphQLUpload } = require('graphql-upload');
See:
https://github.com/jaydenseric/graphql-upload#class-graphqlupload
As a side note, it's a good idea to always use deep imports when they are available:
const GraphQLUpload = require('graphql-upload/public/GraphQLUpload.js');
This way only exactly the JS you need in a given context loads into memory, and if you ever bundle that code you won't rely on slow and unreliable "tree-shaking".
Thanks for the response, good spotting on that one, but i just checked the old code and it looks like it was using GraphQLUpload
where it was broken (sorry i copied a commented section for that particular line, without actually checking if it was the right import from graphql-upload
)
What's happening is the GraphQLUpload
scalar is receiving a value that was not created using graphqlUploadExpress
middleware from the same graphql-upload
installation.
You could try running npm ls graphql-upload
to check if there are multiple installations in node_modules
, and if there are, either dedupe the installation so there is one (update dependencies, etc.), or make sure that at the very least your middleware and scalar are importing from the same one.
If that is not the problem, what might be happening is something relating to the Apollo federation stuff is replacing the GraphQLUpload
scalar with their own substitute that can deal with forwarding the upload values across schemas. I'm not sure the right way to set that up, but maybe you need to import their special GraphQLUpload
scalar in your codebase instead of the official graphql-upload
one, or maybe they just have a bug you need to investigate.
Yeah we read all the related issues on this repo and checked npm ls graohql-upload
but can't see any duplicates.
We even changed our apollo server to match your examples (to remove any magical graphql upload auto configuration happening).
Good point about checking if @apollo/federation
is interfering. Not sure where to start on that but we'll have a go looking into that and report back.
Thanks for being so responsive and helpful <3
This could be useful for people running federation with a gateway
https://medium.com/profusion-engineering/file-uploads-graphql-and-apollo-federation-c5a878707f4c
Closing because I don't think anything is actionable here, but feel free to continue the conversation or share tips for anyone else in the same boat.
Issue
When uploading a file:
using
graphql-upload
, I get back an error:Stack:
Client side
Server side
We found that the issue came from the
parseValue
part of the Upload scalar:https://github.com/jaydenseric/graphql-upload/blob/bdb5f808e0d514c28c0f59c1abd71680aba29bae/public/GraphQLUpload.js#L82
We just added a temporary fix that doesn't check:
if (value instanceof Upload) return value.promise;
and does this instead:return value.promise
Tried looking at the tests in this module and many other ones, but couldnt find a good example of a test that shows what value should look like.
Other details