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

There can be only one type named "Upload" #240

Closed sittingbool closed 3 years ago

sittingbool commented 3 years ago

Hi, I would like to use this with the following setup:

Code in resolver:

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

...

@Mutation(returns => UserModel)
uploadUserAvatar(@Arg('file', () => GraphQLUpload) file: FileUpload) {

Once I start up the server I am getting an error:

Error: There can be only one type named "Upload".
    at assertValidSDL (/path/to/my/project/node_modules/graphql/validation/validate.js:107:11)
    at Object.buildASTSchema (/path/to/my/project/node_modules/graphql/utilities/buildASTSchema.js:45:34)
    at Object.buildSchemaFromTypeDefinitions (/path/to/my/project/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:25:28)
    at Object.makeExecutableSchema (/path/to/my/project/node_modules/graphql-tools/dist/makeExecutableSchema.js:26:29)
    at ApolloServer.initSchema (/path/to/my/project/node_modules/apollo-server-core/dist/ApolloServer.js:264:49)
    at new ApolloServerBase (/path/to/my/project/node_modules/apollo-server-core/dist/ApolloServer.js:159:30)
    at new ApolloServer (/path/to/my/project/node_modules/apollo-server-express/dist/ApolloServer.js:60:9)
    at createApolloServer (/path/to/my/project/app/api/api.js:79:20)
    at /path/to/my/project/app/api/api.js:67:9

Does anyone know how to solve this?

jaydenseric commented 3 years ago

Apollo Server ships with an outdated version of graphql-upload; you need to disable their implementation and setup the current version of graphql-upload yourself, otherwise the two graphql-upload integrations will conflict. Please refer to Apollo for support with their products.

geoyws commented 3 years ago

image

Also, if you are using a monorepo, make sure that all graphql-upload versions are similar, otherwise Upload will be registered twice and you'll get Error: There can be only one type named "Upload". Just encountered that this afternoon.