fix: GraphQL 비로그인 요청에서 CurrentUser 데코레이터 500 오류 수정 - #170
Conversation
GraphQL 컨텍스트에서 req.user가 없으면 HTTP 폴백으로 내려갔는데, GraphQL ExecutionContext의 switchToHttp().getRequest()는 resolver root(args[0])를 반환하므로 루트 Query 비로그인 요청이 전부 TypeError(500)로 실패했다. 컨텍스트 타입 분기로 폴백을 차단한다. spec mock도 실제 ExecutionContextHost 동작(getRequest()=args[0])에 맞게 고치고 비로그인 회귀 케이스를 추가한다.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧹 knip — dead-code 리포트전체 리포트
|
🩺 NestJS Doctor — 89/100 (Good)진단 270건 (error 0).
architecture / security 상위 항목
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Coverage report
Test suite run success1464 tests passing in 173 suites. Report generated by 🧪jest coverage report action from d092e9e |
Summary
FE 연동 중 보고된 버그 수정:
OptionalJwtAuthGuard+@CurrentUser()를 쓰는 public GraphQL query(storeReviews,storeDetail,productReviews,productDetail등)가 비로그인 요청에서 전부 500으로 실패하던 문제를 수정한다.currentUserFactory가 GraphQL 컨텍스트에서req.user가 없으면 HTTP 폴백으로 내려가는데, GraphQL ExecutionContext의switchToHttp().getRequest()는 HTTP request가 아니라 resolver root(args[0]) 를 반환한다. 루트 Query의 root는undefined이므로request.user에서TypeError→ 500.ctx.getType<GqlContextType>() === 'graphql'분기로 GraphQL 요청이 HTTP 경로로 폴백하지 않게 차단.Scope
src/global/auth/decorators/current-user.decorator.ts— 컨텍스트 타입 분기src/global/auth/decorators/current-user.decorator.spec.ts— mock을 실제ExecutionContextHost동작(getRequest() = args[0])에 맞게 재작성 + 비로그인 회귀 케이스 추가진행 상황
getRequest()가 항상 객체를 반환해 버그를 가렸음)yarn validate통과 (lint + tsc + dto:check + arch:check + test:cov 1464건)Impact
@CurrentUser()inauth.controller) 경로는 동작 변화 없음.Test plan
req.user반환undefined반환 (회귀 케이스 — 구 코드에서는 TypeError)request.user/undefined반환