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.42k stars 131 forks source link

FileUpload - where is fileName, mimetype and createReadStream ? #367

Closed SebaBoler closed 1 year ago

SebaBoler commented 1 year ago

I have migrated to the new version from 13 to 16.0.2 But have issue about FileUpload TS2304: Cannot find name 'FileUpload'.

I need to change to Upload ?

I didn't find anything about conversion from FileUpload to Upload in documentation

SebaBoler commented 1 year ago

Didnt find any good documentation to migration process from 13 to 16

in entity if you use FileUpload now you will use the same from import FileUpload from 'graphql-upload/Upload.mjs';

But if you have like me const { fileName, mimetype, createReadStream } = file will not work and didn't find any docs

jaydenseric commented 1 year ago

Didnt find any good documentation to migration process from 13 to 16

Not sure why you would say this when the changelog entries for each major version explains the breaking changes, and specifically has code examples for how to migrate the import paths, e.g:

Screenshot 2023-03-23 at 8 26 56 am

You can also see the same changelog content in the GitHub release descriptions:

https://github.com/jaydenseric/graphql-upload/releases

But if you have like me const { fileName, mimetype, createReadStream } = file will not work and didn't find any docs

This is not worded well. Docs for what exactly? How to use the upload scalar in resolvers? That is documented:

https://github.com/jaydenseric/graphql-upload/blob/e01b5d5541760d529b06c900883c5fa7febcff00/GraphQLUpload.mjs#L53

And there is a working example of this:

https://github.com/jaydenseric/apollo-upload-examples/blob/a5da903448e31abaf718be6a21d13d253fc3983b/api/storeUpload.mjs#L17

You need to await the file upload promise to be able to access the data.

nicostubi commented 1 year ago

@jaydenseric I am not sure this answers the question about the type FileUpload.

At least, not for me.

jaydenseric commented 1 year ago

@nicostubi if you just need the TypeScript type for what it resolves, you can do it like this in JS via JSDoc:

https://github.com/jaydenseric/apollo-upload-examples/blob/a5da903448e31abaf718be6a21d13d253fc3983b/api/storeUpload.mjs#L12

And like this in a TS module:

import type { FileUpload } from "graphql-upload/processRequest.mjs";
nicostubi commented 1 year ago

Thank you.

I've tried both:

const GraphQLUpload_mjs_1 = require("graphql-upload/GraphQLUpload.mjs");
                            ^
Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/node_modules/graphql-upload/GraphQLUpload.mjs not supported.
nicostubi commented 1 year ago

This is probably due to the fact that my NestJS backend compiles with module commonjs

samihuc commented 1 year ago

@nicostubi if you just need the TypeScript type for what it resolves, you can do it like this in JS via JSDoc:

https://github.com/jaydenseric/apollo-upload-examples/blob/a5da903448e31abaf718be6a21d13d253fc3983b/api/storeUpload.mjs#L12

And like this in a TS module:

import type { FileUpload } from "graphql-upload/processRequest.mjs";

It would be great to add this to the changelog for these releases. I had the same problem and couldn't find a solution anywhere, I just ended up copying the interface from version 13 because I couldn't find it in the new version or the changelog/docs and assumed it was removed... because there were no instructions on how to migrate this to the new file structure:

import { FileUpload } from 'graphql-upload';

And then I stumbled on this while searching for my other problem, which is the error nicostubi had.

samihuc commented 1 year ago

Also, to be clear for anyone facing similar issues: the maintainer's answer only applies to version 16+. If you are on version 15, (or earlier?), FileUpload is found here:

import type { FileUpload } from 'graphql-upload/Upload.js';

(Again, if we are required to deeply import things then it also needs to be in the changelog when things move around between files.)