Skip to content

Incompatibility of ValidationPipe with graphql-upload #1004

@VictorAssis

Description

@VictorAssis

Bug Report

Current behavior

When i create a DTO for my mutation having a FileUpload field and binding the ValidationPipe, i get the error:

TypeError: Promise resolver undefined is not a function
    at new Promise (<anonymous>)
    at TransformOperationExecutor.transform (/Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/class-transformer/TransformOperationExecutor.js:117:32)
    at _loop_1 (/Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/class-transformer/TransformOperationExecutor.js:235:45)
    at TransformOperationExecutor.transform (/Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/class-transformer/TransformOperationExecutor.js:260:17)
    at ClassTransformer.plainToClass (/Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/class-transformer/ClassTransformer.js:17:25)
    at Object.plainToClass (/Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/class-transformer/index.js:20:29)
    at ValidationPipe.transform (/Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/@nestjs/common/pipes/validation.pipe.js:41:39)
    at /Users/victorassis/Workspace/barreiroclub/nestjs-graphql-upload-error/node_modules/@nestjs/core/pipes/pipes-consumer.js:16:33
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Input Code

I created the repo https://github.com/VictorAssis/nestjs-graphql-upload-error with a resolver called CategoriesResolver that demonstrates the upload working witthout ValidationPipe and with ValidationPipe but without DTO and the case when occurs error (with ValidationPipe and with DTO).

// CategoriesResolver
@Mutation(returns => String)
  @UsePipes(ValidationPipe)
  async createWithDtoWithValidation (@Args() newCategory: NewCategoryInput) {
    const file = await newCategory.file
    return `It does not work ${file.filename}`
  }

// NewCategoryInput
@ArgsType()
export class NewCategoryInput {
  @Field()
  @IsString()
  @MinLength(3, { message: 'Name too short.' })
  name: string;

  @Field(type => GraphQLUpload)
  file: FileUpload
}

Expected behavior

Receive the Promise in my resolver as when I'm not using ValidationPipe.

Possible Solution

I tried to set transform: false in the ValidationPipe options but was ignored.

Another attempt was to set @Exclude for the property in the DTO, but the property did not come in the resolver method.

Environment


Nest version: 7.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions