소개

Nest.js 공식 문서를 참고하면 GraphQL 사용 시 Execution context를 받을 경우 GqlExecutionContext를 거치라고 나온다. 문서 링크

일반적인 context의 request

GraphQL을 안쓰는 경우 다음과 같이 사용한다.

async canActivate(context: ExecutionContext) {
const req = context.switchToHttp().getRequest();
}

GraphQL에서 context의 request

GqlExecutionContext를 거치고도 switchToHttp 함수는 존재하지만, 안에 있는 getRequest 를 사용하면 undefined를 반환한다.

GraphQL에서는 다음과 같이 사용할 수 있다.

async canActivate(context: ExecutionContext) {
const ctx = GqlExecutionContext.create(context);
const req = ctx.getContext().req;
}

참고 문서

태그
nestjs
반응과 댓글 시스템은 Giscus에 의해 호스팅되며, 모든 대화는 GitHub에 저장됩니다.

출처가 명확하지 않은 내용을 신뢰하지 마세요. 글 작성자는 이로 인해 발생하는 책임을 지지 않습니다.

피드백 무엇이든 환영합니다 🤗

doda.devlicensegithubmade with ☕️