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

Final Typescript Support #343

Closed Tjerk-Haaye-Henricus closed 1 year ago

Tjerk-Haaye-Henricus commented 1 year ago

Hey There, first of all I'm really thankful for this library.

I'm using it since a long time now. Since the world seems to switch to esm i would do so too. But unfortunately since this moment this library does not work anymore.

I'm using it along with type-graphql so i really really need types without that i'm not able to upload files. Of course I've already added an issue over there to make sure i will find a solution.

Nevertheless...

While importing the files

image
Could not find a declaration file for module 'graphql-upload/Upload.mjs'. 'node_modules/graphql-upload/Upload.mjs' implicitly has an 'any' type.

This is my tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": ".",
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "lib": ["es2018", "esnext.asynciterable"],
    "module": "esnext",
    "moduleResolution": "nodenext",
    "outDir": "build",
    "removeComments": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2018"
  },
  "include": ["source"],
  "exclude": ["build"]
}

Maybe I'm doing something wrong but i really don't know what.

I read along alot of issues about this topic and it seems that a lot of people feel with me. For me this is a really hard situation because without types in such a central part of my application it feels like no good deal to me using this library. It's not possible to me, to change my typescript configuration to commonjs to make a single library work.

I can really understand that maintaining a library as famous as this one is a real hard thing. And i'm really thankful that you've spend so much time creating this library.

While reading i did not really get the point of not using typescript here. Wouldnt it be much easier to do it in Typescript since there are so much people out there using it?

So i have at least two Questions.

Will there ever be proper types for this package ? If not is there a package which you might know solving my problems uploading Files with proper typings.

Tjerk-Haaye-Henricus commented 1 year ago

btw: Here the link to type-graphql https://github.com/MichalLytek/type-graphql/issues/1372

jaydenseric commented 1 year ago

While reading i did not really get the point of not using typescript here.

This project has 100% type safety, checked with TypeScript:

https://github.com/jaydenseric/graphql-upload/blob/e01b5d5541760d529b06c900883c5fa7febcff00/package.json#L91

Having types held in the actual module that is being used is superior to having definition files seperate to the module, for reasons that have been explained in detail in various other issues and PR's. For example, Deno users can import those modules via HTTP imports from a CDN that statically hosts the package. For everyone, it's super nice being able to CMD+Click on code and make your way to the source module and see the real source code instead of going to some seperate definition file.

Some suggestions to try to fix your TS config:

Maybe try TS compiling a module that imports from graphql-upload, then look at the resulting .js or .mjs file that's emitted and see if the import it's creating makes sense; you could even try running it with Node.js to check if Node.js is able to resolve the import ok.

Tjerk-Haaye-Henricus commented 1 year ago

Thanks 1000 Times for the quick reply :)

Ahh so it's maybe on my side to add some knowledge in that particular topic too :) I would like to move to bun when it becomes usable in production maybe i need to go that direction there too :)

I know that this is definitively a way to much questions but do you have an idea why type-graphql cannot infer graphql types from that library anymore ? In the old package apollo-upload-server it was possible. I've added a issue on type-graphql aswell https://github.com/MichalLytek/type-graphql/issues/1372

Maybe you know how to deal with that :)

thanks so far already 🙏 🙏 🙏

jaydenseric commented 1 year ago

You're welcome :)

do you have an idea why type-graphql cannot infer graphql types from that library anymore ?

I'm not the best person to ask; I don't use or maintain type-graphql.

Closing because there doesn't appear to be anything to action here in this repo; if something comes up during the investigation in https://github.com/MichalLytek/type-graphql/issues/1372 that should be actioned here we can reopen.

Tjerk-Haaye-Henricus commented 1 year ago

Yes i will keep you updated in case someone is using type-graphql as i do :) Thanks again for the support 🙏