バージョン
6.7.1
結論
Expressのresだった
きっかけ
GraphQLとpassportの連携時
import { ExecutionContext, Injectable, Logger } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class GqlAuthGuard extends AuthGuard('oauth2-client-password') {
getRequest(context: ExecutionContext) {
const ctx = GqlExecutionContext.create(context);
const request = ctx.getContext().req;
/*
for (var n in request) {
if (typeof request[n] === 'function') {
Logger.log(n);
}
}
*/
Logger.log(request.params);
Logger.log(request.body);
Logger.log(request.query);
return request;
}
}
ちなみに、graphql-tag
でrequest.body.query
をパースした結果
{
"kind": "Document",
"definitions": [
{
"kind": "OperationDefinition",
"operation": "mutation",
"variableDefinitions": [],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "login"
},
"arguments": [
{
"kind": "Argument",
"name": {
"kind": "Name",
"value": "client_id"
},
"value": {
"kind": "StringValue",
"value": "demo",
"block": false
}
},
{
"kind": "Argument",
"name": {
"kind": "Name",
"value": "client_secret"
},
"value": {
"kind": "StringValue",
"value": "abcdefgh",
"block": false
}
}
],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "accessToken"
},
"arguments": [],
"directives": []
}
]
}
}
]
}
}
],
"loc": {
"start": 0,
"end": 101
}
}