3

我需要以某种方式objectId@Args警卫内部访问,以检查发件人是否已将其objectId分配给他的帐户。知道如何实施吗?

 @Query(() => [Person])
      @UseGuards(ObjectMatch)
      async pplWithObject(@Args('objectId') id: string): Promise<Person[]> {
        return await this.objService.getPeopleWithObject(id);
      }

是否可以从上下文访问传递的参数?

const ctx = GqlExecutionContext.create(context);
    const request = ctx.getContext().req;
4

1 回答 1

3

您可以使用 GqlExecutionContext ,例如:

const ctx = GqlExecutionContext.create(context);
console.log(ctx.getArgs()) // object with your query args
ctx.getArgs()['objectId']

@nestjs/graphql 版本:^7.6.0

于 2020-08-25T19:36:10.403 回答