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

GraphQL can`t determine input type for file in upload file resolver for NestJS #316

Closed osipMax closed 2 years ago

osipMax commented 2 years ago

Hi! Thanks for spending your time on this module! I'm working with NestJS and Graphql and I need to upload files to Apollo Server. But after changing this package graphql showing this error

Error: Cannot determine a GraphQL input type nullfor the "file".

So can you help me, how should I specify the type of file in this case? Before updating to version v15 all worked as expected

I've updated imports to current version but it didn't help

import { FileUpload, GraphQLUpload } from 'graphql-upload/GraphQLUpload.js';

image
jaydenseric commented 2 years ago

I've updated imports to current version but it didn't help

import { FileUpload, GraphQLUpload } from 'graphql-upload/GraphQLUpload.js';

It needs to be like this (assuming your are using TypeScript to compile this code):

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

Hope that helps :)

werkshy commented 2 years ago

@jaydenseric thanks for keeping up with all of us having trouble with the module change.

I almost opened an issue just like this one when I couldn't get the new module changes to work in my project, but found there was one last tsconfig setting I needed: allowJs: true - perhaps recommend that to anyone having trouble with types after making the changes to imports and uninstalling @types/graphql-upload.

jaydenseric commented 2 years ago

@werkshy you might need that if you are using tsconfig.json; if you are using jsconfig.json TypeScript automatically sets allowJs to true for you:

https://code.visualstudio.com/docs/languages/jsconfig#_what-is-jsconfigjson

I use jsconfig.json in my projects because I only use JavaScript files (.js/.mjs) and don't use .ts/.mts/.cts with a compile step.