【问题标题】:How to add decorator to args param in graphql如何在graphql中将装饰器添加到args参数
【发布时间】:2021-12-24 19:44:45
【问题描述】:

无法将装饰器 @IsUUID()class-validator 添加到我的参数 productI,我不想使用额外的 dto。如何解决?

@UseGuards(new AuthGuard(['user', 'admin']))
@Mutation(() => ProductEntity)
async updateProduct(
  @User() user,
  @Args('productId', {})
  //@IsUUID() Unable to resolve signature of parameter decorator when called as an expression.
  productId: string,
  @Args('inputs', {})
  inputs: UpdateProductInputDto,
): Promise<ProductEntity> {
  return this.productService.updateProduct(user.id, productId, inputs);
}

【问题讨论】:

    标签: typescript graphql nestjs


    【解决方案1】:

    没有办法解决它。如果您想使用 @IsUUID()ValidationPipe,您必须使用类 DTO。如果你只是想验证UUID,你可以使用ParseUUIDPipe@Args('productId', {}, new ParseUUIDPipe({ version: 4 }))

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 2014-04-26
      • 2010-12-23
      • 2017-03-07
      • 2018-06-05
      • 1970-01-01
      • 2020-11-06
      • 2020-07-15
      • 1970-01-01
      相关资源
      最近更新 更多