Skip to content

feat(common): A-2 DTO 검증 인프라 + SDL 동기화 가드 도입#96

Merged
chanwoo7 merged 2 commits into
mainfrom
chore/dto-validation-infra
May 23, 2026
Merged

feat(common): A-2 DTO 검증 인프라 + SDL 동기화 가드 도입#96
chanwoo7 merged 2 commits into
mainfrom
chore/dto-validation-infra

Conversation

@chanwoo7
Copy link
Copy Markdown
Member

@chanwoo7 chanwoo7 commented May 23, 2026

Summary

  • PaginationInput / CursorInput base DTO + IsDecimalString / IsTimeString 커스텀 validator 추가. 향후 도메인별 Input class 가 베이스를 상속하여 사용 (offset/limit/cursor/decimal/time 검증 통합)
  • SDL ↔ DTO 동기화 검사 스크립트 (yarn dto:check) 추가. 마이그레이션 진행 중에는 warning 모드로 CI 정보만 출력. 전수 DTO 화 완료 후 --strict 로 격상 예정
  • 본 PR 단독으로는 도메인 동작에 영향 없음. 후속 PR(Auth REST → User Input → Seller Input)에서 실제 검증 적용

배경

A-2 검증 전략(GraphQL Input · REST Body 모두 class + class-validator 로 통일) 도입의 1차 인프라 PR. SDL 단일 소스는 유지하되, codegen interface 는 Resolver 반환 타입용, 검증은 class DTO 경유.

현재 산재된 수동 검증 25곳 이상(offset/limit, nickname 정규식, birthDate, rating, price, 영업시간 등)을 데코레이터로 흡수해갈 예정.

후속 작업 (별도 PR)

  • P0-3 단계 2: Auth REST Body 3종 DTO 화 (SellerLoginInput 등)
  • P0-3 단계 3·4: User · Seller GraphQL Input 전수 DTO 화
  • 마이그레이션 완료 후 dto:check warning → strict 승격

Test plan

  • 로컬 yarn lint 통과
  • 로컬 yarn test 918/918 통과 (회귀 없음)
  • 로컬 yarn dto:check 실행: 46 SDL inputs · 2 DTO base · errors 0
  • CI: lint / type-check / test:cov 통과
  • CI: dto:check warning step info 46건 출력 후 정상 종료 (실패 안 함)

Summary by CodeRabbit

릴리스 노트

  • New Features

    • 페이지네이션 입력 타입 추가 (오프셋/리밋, 커서 기반)
    • 소수 문자열 및 시간 형식 검증 기능 추가
  • Tests

    • 페이지네이션 입력 검증 테스트 추가
    • 커스텀 검증기 유닛 테스트 추가
  • Chores

    • CI 워크플로우에 동기화 검사 단계 추가
    • 검증 스크립트 및 패키지 스크립트 구성

Review Change Stack

chanwoo7 added 2 commits May 23, 2026 23:30
A-2 검증 전략(class-validator 전면 도입) 인프라.

- PaginationInput / CursorInput: 산재된 offset/limit/cursor 검증을
  단일 베이스 클래스로 통합. limit 상한 100 운영 보호.
- IsDecimalString / IsTimeString: seller 도메인 가격·영업시간 입력의
  수동 검증을 데코레이터화. 향후 SDL Input DTO 에서 재사용.
- 단위 테스트 36건 동반 (validate 결과 직접 검증)
A-2 전략에 따라 SDL input 정의와 DTO class 의 어긋남을 빌드 시점에
탐지. 마이그레이션 진행 중에는 warning 모드로 정보만 출력하고
CI 를 실패시키지 않는다. 모든 도메인 DTO 화 완료 후 --strict 로
승격하여 필수 status check 로 격상 예정.

- scripts/check-graphql-dto-sync.ts: ts-morph 기반 비교 스크립트
- package.json: yarn dto:check 추가
- pr-check.yml: Lint 단계 직후 warning 모드 실행
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

개요

이 PR은 GraphQL SDL과 TypeScript DTO 간 동기화를 자동으로 검사하는 CI 도구를 추가하고, 페이지네이션 및 검증 기능을 위한 공통 DTO와 커스텀 검증기를 새로 도입합니다.

변경 사항

GraphQL DTO 동기화 검증 도구

계층 / 파일(s) 요약
CI 워크플로우 및 실행 설정
.github/workflows/pr-check.yml, package.json
PR 체크 워크플로우의 린트 단계 뒤에 yarn dto:check --warning 스텝을 추가하여 DTO↔SDL 동기화를 경고 모드로 검사합니다.
DTO↔SDL 동기화 검증 스크립트
scripts/check-graphql-dto-sync.ts
GraphQL 파일을 파싱하여 SDL input 정의를 추출하고, ts-morph로 TypeScript DTO 클래스를 분석하여 필드명, 필수 여부를 비교합니다. 엄격 모드(--strict)와 경고 모드(--warning)를 지원하며, 불일치 사항을 [MISSING_DTO], [FIELD_MISSING], [EXTRA_DTO_FIELD], [REQUIRED_MISMATCH] 형태로 보고합니다.

공통 페이지네이션 및 검증 기능

계층 / 파일(s) 요약
PaginationInput 및 CursorInput DTO
src/common/dto/pagination.input.ts, src/common/dto/pagination.input.spec.ts, src/common/dto/cursor.input.ts, src/common/dto/cursor.input.spec.ts
Offset/limit 기반과 cursor 기반 두 가지 페이지네이션 DTO를 class-validator 데코레이터로 정의합니다. offset은 0 이상, limit과 cursor는 1~100 범위로 검증되며, 각각의 유효/무효 입력 조합에 대한 검증 테스트를 포함합니다.
IsDecimalString 검증기
src/common/validators/decimal-string.validator.ts, src/common/validators/decimal-string.validator.spec.ts
정규식 ^-?\d+(\.\d+)?$으로 소수점과 음수를 포함한 10진 문자열 형식을 검증하는 커스텀 class-validator 데코레이터를 구현합니다. 유효 케이스(정수, 소수, 음수)와 무효 케이스(통화 기호, 지수 표기 등)를 테스트합니다.
IsTimeString 검증기
src/common/validators/time-string.validator.ts, src/common/validators/time-string.validator.spec.ts
정규식 /^([01]\d|2[0-3]):[0-5]\d$/으로 HH:MM 24시간제 형식(00:00~23:59)을 검증하는 커스텀 class-validator 데코레이터를 구현합니다. 유효한 시간 형식과 무효한 입력(범위 초과, 포맷 불일치 등)을 테스트합니다.

예상 코드 리뷰 노력

🎯 3 (보통) | ⏱️ ~20분

관련 가능성 있는 PR

  • CaQuick/caquick-be#14: 동일하게 CI GitHub Actions 워크플로우를 변경하며, 특히 .github/workflows/pr-check.yml에 추가 검증 단계를 실행하도록 구성한 점에서 직접적으로 연결됩니다.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 변경 내용의 핵심(DTO 검증 인프라 도입과 SDL 동기화 가드)을 명확하게 설명하고 있으며, 전체 changeset과 일치합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/dto-validation-infra

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 96.74% 2939/3038
🟢 Branches 86.59% 1659/1916
🟢 Functions 93.42% 625/669
🟢 Lines 97.06% 2677/2758

Test suite run success

918 tests passing in 82 suites.

Report generated by 🧪jest coverage report action from 6eef859

@chanwoo7 chanwoo7 merged commit 6f7aed6 into main May 23, 2026
9 of 10 checks passed
@chanwoo7 chanwoo7 deleted the chore/dto-validation-infra branch May 23, 2026 17:36
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6eef859ddd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +235 to +239
if (WARNING_ONLY) {
console.warn(
'\n[warning mode] CI 를 실패시키지 않습니다. 마이그레이션 완료 후 warning 플래그 제거 + --strict 로 승격하세요.',
);
process.exit(0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail CI when SDL/DTO mismatches are detected

In warning mode this block always exits with code 0 even after collecting FIELD_MISSING, EXTRA_DTO_FIELD, or REQUIRED_MISMATCH errors, so the new CI step (.github/workflows/pr-check.yml runs yarn dto:check --warning) will not block merges when already-migrated DTOs drift from SDL. That defeats the guardrail for real schema/validation divergence and can let runtime validation mismatches ship unnoticed.

Useful? React with 👍 / 👎.

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