Skip to content

fix: GraphQL 비로그인 요청에서 CurrentUser 데코레이터 500 오류 수정 - #170

Merged
chanwoo7 merged 1 commit into
developfrom
fix/current-user-graphql-fallback
Aug 5, 2026
Merged

fix: GraphQL 비로그인 요청에서 CurrentUser 데코레이터 500 오류 수정#170
chanwoo7 merged 1 commit into
developfrom
fix/current-user-graphql-fallback

Conversation

@chanwoo7

@chanwoo7 chanwoo7 commented Aug 5, 2026

Copy link
Copy Markdown
Member

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])에 맞게 재작성 + 비로그인 회귀 케이스 추가

진행 상황

  • 데코레이터 컨텍스트 타입 분기 수정
  • spec mock 실제 동작 정합화 (기존 mock은 getRequest()가 항상 객체를 반환해 버그를 가렸음)
  • GraphQL 비로그인 회귀 테스트 추가
  • yarn validate 통과 (lint + tsc + dto:check + arch:check + test:cov 1464건)

Impact

  • 비로그인 사용자의 public query 접근이 정상화된다 (매장 상세/리뷰, 상품 상세/리뷰 화면).
  • 로그인 사용자·REST(@CurrentUser() in auth.controller) 경로는 동작 변화 없음.
  • 스키마/API 계약 변경 없음.

Test plan

  • GraphQL + 로그인: req.user 반환
  • GraphQL + 비로그인: 크래시 없이 undefined 반환 (회귀 케이스 — 구 코드에서는 TypeError)
  • HTTP + user 유/무: request.user / undefined 반환

GraphQL 컨텍스트에서 req.user가 없으면 HTTP 폴백으로 내려갔는데,
GraphQL ExecutionContext의 switchToHttp().getRequest()는 resolver
root(args[0])를 반환하므로 루트 Query 비로그인 요청이 전부
TypeError(500)로 실패했다. 컨텍스트 타입 분기로 폴백을 차단한다.

spec mock도 실제 ExecutionContextHost 동작(getRequest()=args[0])에
맞게 고치고 비로그인 회귀 케이스를 추가한다.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: de898dcd-a505-4ce0-80d1-4eb912e6cac0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🧹 knip — dead-code 리포트

요약 항목 없음
전체 리포트
(knip 출력 없음 — 이슈 0이거나 실행 실패)

청소 후보(오탐 가능) · 기준 docs/guide/architecture-conventions.md

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🩺 NestJS Doctor — 89/100 (Good)

진단 270건 (error 0).

Category error warning info
architecture 0 0 13
correctness 0 118 0
performance 0 24 16
schema 0 0 86
security 0 13 0
architecture / security 상위 항목
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal type 'IAuditLogRepository'.
  • warning security/security/no-exposed-env-vars: Direct 'process.env.NODE_ENV' access in 'AuthController'. Use ConfigService instead.
  • warning security/security/require-guards-on-endpoints: Endpoint 'start' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'callback' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'refresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'logout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerLogin' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerRefresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerLogout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'devIssueToken' has no @UseGuards() at class or method level.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal module '@/features/conversation/repositories/conversation.repository'.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal type 'ConversationRepository'.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal module '@/features/order/repositories/order.repository'.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal type 'OrderRepository'.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal module '@/features/product/repositories/product.repository'.

오탐 포함 가능 · 기준 docs/guide/architecture-conventions.md

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 97.68% 4299/4401
🟢 Branches 93.67% 1362/1454
🟢 Functions 95.62% 829/867
🟢 Lines 98.1% 3917/3993

Test suite run success

1464 tests passing in 173 suites.

Report generated by 🧪jest coverage report action from d092e9e

@chanwoo7
chanwoo7 merged commit 0cae77f into develop Aug 5, 2026
12 checks passed
@chanwoo7
chanwoo7 deleted the fix/current-user-graphql-fallback branch August 5, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant