jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Wrong documentation or miss understanding ? #285

Closed antunespedro80 closed 2 years ago

antunespedro80 commented 2 years ago

Hi! I was reading your documentation and there, you show that FileUpload interface is an interface with:

So, what happens ? When I try to do a stream like const stream = file.createReadStream(), I have an exception like "file.createReadStream is not a function".

package.json graphql-upload@^13.0.0 @types/graphql-upload@^8.0.7

jaydenseric commented 2 years ago

What the Upload scalar promise resolves is fully documented in the readme:

https://github.com/jaydenseric/graphql-upload/tree/v13.0.0#type-fileupload

However, on index.d.ts, you show that interface FileUpload consists of:

I don't show that; the @types/graphql-upload package is not maintained by me. Feel free to PR Definitely Typed to update those types if any are wrong.

I have an exception like "file.createReadStream is not a function".

Do you have a runtime exception, or are you talking about a TypeScript type check error message?

antunespedro80 commented 2 years ago

I don't show that; the @types/graphql-upload package is not maintained by me. Feel free to PR Definitely Typed to update those types if any are wrong.

Yeah, you're right, my bad...

Do you have a runtime exception, or are you talking about a TypeScript type check error message?

Both

jaydenseric commented 2 years ago

If you run npm ls graphql-upload within your project, do you see multiple versions of graphql-upload installed?

antunespedro80 commented 2 years ago

Nop, only graphql-upload@13.0.0

jaydenseric commented 2 years ago

If you console.log what the awaited Upload scalar promise resolves in the resolvers, what do you see?

antunespedro80 commented 2 years ago

image

jaydenseric commented 2 years ago

It looks like it is working… you're supposed to await the upload, then you can do .createReadStream() on what it resolves.

antunespedro80 commented 2 years ago

Yeah, but when I try to do .createReadStream(), triggers the exception file.createReadStream is not a function

jaydenseric commented 2 years ago

That is really strange. Maybe you are not using the GraphQLUpload scalar exported from graphql-upload, but another one?

If you reach into node_modules, and put a console.log just before these lines, do both log when you run into the problem?

antunespedro80 commented 2 years ago

Yes, I can console.log both lines, 278 and 81

jaydenseric commented 2 years ago

I just updated the example API to use the latest graphql and graphql-upload versions, and everything works fine:

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

There is something funky going on in your project.

jaydenseric commented 2 years ago

Closing because this problem couldn't be reproduced, so there is nothing I can action from here. If you manage to put together a minimal project (vanilla Node.js, no TypeScript or other build tools) that demonstrates a specific bug in this graphql-upload package we can reopen and investigate further.

antunespedro80 commented 2 years ago

Ok, thanks for the help, I will try do my best to replicate this. I'm using this with nestjs, I don't know if it is the problem or not... But, no problem, I will figure this out.

Thanks a lot!