Search code examples
typescriptexpressapollo-servertypegraphql

Error: There can be only one type named "Upload" - Apollo, Express, Type-Graphql


I am trying to run a simple Mutation in order to Upload an Image, but I am stack with this error: "Error: There can be only one type named "Upload"."

this is my code

import { FileUploadI, GraphQLUpload } from 'graphql-upload'

@Mutation(() => Picture)
  async uploadPicture(@Arg('data', () => GraphQLUpload) data: FileUploadI): Promise<Picture> {
    //.. implementation
  }

I am using Apollo and Express as Server and Typescript with Type-Graphql


Solution

  • The reason of this Error is Apollo 2.0 "File Upload" feature.

    You can read more about this feature in follow link:

    https://www.apollographql.com/blog/file-uploads-with-apollo-server-2-0-5db2f3f60675

    the package 'graphql-upload' has scalar type Upload and Apollo server use 'graphql-upload' to handle file uploads too.

    Maybe you can solve this problem using the apollo "file upload" feature, or, renaming the Upload that came from 'graphql-upload'.