6

I need the to somehow access the objectId from @Args inside the guard so as to check if the sender has the objectId assigned to his account. Any idea how I could implement it?

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

Is it possible to access the passed argument from the context?

const ctx = GqlExecutionContext.create(context);
    const request = ctx.getContext().req;
h4sop
  • 139
  • 9

1 Answers1

8

You can use GqlExecutionContext for it, like:

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

@nestjs/graphql version: ^7.6.0

Natan Deitch
  • 556
  • 8
  • 12