问题描述
我需要通过某种方式从防护装置内的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;
解决方法
您可以为其使用GqlExecutionContext,例如:
const ctx = GqlExecutionContext.create(context);
console.log(ctx.getArgs()) // object with your query args
ctx.getArgs()['objectId']
@ nestjs / graphql版本:^ 7.6.0