docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
---
|
||||
id: wiki-2026-0508-codegen
|
||||
title: Codegen (GraphQL, OpenAPI, Schema-driven)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Code Generation, GraphQL Codegen, OpenAPI Codegen]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [codegen, graphql, openapi, typescript, tooling]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: TypeScript
|
||||
framework: GraphQL Code Generator / openapi-typescript
|
||||
---
|
||||
|
||||
# Codegen (Schema-driven Code Generation)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 schema 가 single source of truth"**. Codegen 은 GraphQL/OpenAPI/Protobuf schema 에서 type 과 client code 를 자동 생성 — 매 manual sync 의 X, drift 의 zero, refactor 매 compile-time safe.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 주요 도구 (2026)
|
||||
- **GraphQL**: `@graphql-codegen/cli` (client preset), `gql.tada` (zero-config inline).
|
||||
- **OpenAPI**: `openapi-typescript` (types), `openapi-fetch` (typed client), `orval` (React Query hooks).
|
||||
- **gRPC/Protobuf**: `bufbuild/protobuf-es`, `connect-es`.
|
||||
- **DB schema**: `kysely-codegen`, `drizzle-kit`, Prisma.
|
||||
|
||||
### 매 출력 종류
|
||||
- Type definitions only (lightweight).
|
||||
- Typed client (operations + types).
|
||||
- Hooks/composables (React Query, SWR, urql).
|
||||
- Server stubs (resolvers, controllers).
|
||||
|
||||
### 매 watch vs build-time
|
||||
- Dev: watch mode → 매 save 시 regen.
|
||||
- CI: `--check` 로 매 schema/code drift 검출.
|
||||
- Pre-commit: 매 generated files 매 staged 보장.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### GraphQL client preset (@graphql-codegen/cli)
|
||||
```yaml
|
||||
# codegen.ts
|
||||
import type { CodegenConfig } from '@graphql-codegen/cli';
|
||||
|
||||
const config: CodegenConfig = {
|
||||
schema: 'https://api.example.com/graphql',
|
||||
documents: ['src/**/*.{ts,tsx}'],
|
||||
generates: {
|
||||
'src/gql/': {
|
||||
preset: 'client',
|
||||
config: { useTypeImports: true, scalars: { DateTime: 'string' } },
|
||||
},
|
||||
},
|
||||
};
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Using generated `graphql()` (typed documents)
|
||||
```ts
|
||||
import { graphql } from '@/gql';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
const FlightSearch = graphql(`
|
||||
query FlightSearch($from: String!, $to: String!) {
|
||||
flights(from: $from, to: $to) { id price airline }
|
||||
}
|
||||
`);
|
||||
|
||||
export function useFlights(vars: { from: string; to: string }) {
|
||||
return useQuery({
|
||||
queryKey: ['flights', vars],
|
||||
queryFn: () => request('/graphql', FlightSearch, vars),
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### gql.tada (zero-config alternative)
|
||||
```ts
|
||||
import { graphql } from 'gql.tada';
|
||||
|
||||
const Query = graphql(`
|
||||
query Me { me { id email } }
|
||||
`);
|
||||
// 매 inferred 매 fully typed — no codegen step
|
||||
```
|
||||
|
||||
### openapi-typescript + openapi-fetch
|
||||
```bash
|
||||
npx openapi-typescript ./openapi.yaml -o ./src/api/schema.ts
|
||||
```
|
||||
```ts
|
||||
import createClient from 'openapi-fetch';
|
||||
import type { paths } from './api/schema';
|
||||
|
||||
const api = createClient<paths>({ baseUrl: 'https://api.example.com' });
|
||||
|
||||
const { data, error } = await api.GET('/users/{id}', {
|
||||
params: { path: { id: '42' } },
|
||||
});
|
||||
// data 매 매 fully typed
|
||||
```
|
||||
|
||||
### orval — React Query hooks from OpenAPI
|
||||
```ts
|
||||
// orval.config.ts
|
||||
export default {
|
||||
api: {
|
||||
input: './openapi.yaml',
|
||||
output: {
|
||||
target: './src/api/generated.ts',
|
||||
client: 'react-query',
|
||||
mode: 'tags-split',
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Drizzle Kit — DB schema introspection
|
||||
```bash
|
||||
drizzle-kit introspect:pg --connectionString=$DATABASE_URL --out=./src/db
|
||||
```
|
||||
|
||||
### CI drift check
|
||||
```yaml
|
||||
# .github/workflows/codegen-check.yml
|
||||
- run: pnpm codegen
|
||||
- run: git diff --exit-code src/gql src/api
|
||||
```
|
||||
|
||||
### Husky pre-commit
|
||||
```sh
|
||||
# .husky/pre-commit
|
||||
pnpm codegen && git add src/gql src/api
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | 도구 |
|
||||
|---|---|
|
||||
| GraphQL + React/Vue | `@graphql-codegen` client preset |
|
||||
| GraphQL + want zero step | `gql.tada` |
|
||||
| OpenAPI types only | `openapi-typescript` |
|
||||
| OpenAPI + hooks | `orval` |
|
||||
| DB-first | Drizzle / Prisma / Kysely codegen |
|
||||
|
||||
**기본값**: GraphQL → client preset; REST → `openapi-typescript` + `openapi-fetch`.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Type-Safety]]
|
||||
- 변형: [[OpenAPI]] · [[gRPC]]
|
||||
- 응용: [[React-Query]]
|
||||
- Adjacent: [[Contract-Testing]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: schema-driven API integration / 매 type drift 매 painful 한 monorepo.
|
||||
**언제 X**: 매 throwaway prototype, schema 매 unstable.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Hand-writing GraphQL types**: 매 drift 의 zero-day issue.
|
||||
- **Committing nothing then expecting safety**: 매 generated files 매 commit + CI check 둘 다 필요.
|
||||
- **Running codegen only locally**: 매 CI drift check 의 X 면 PR 매 깨짐.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (the-guild.dev / openapi-ts.dev / orval.dev official docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — codegen tools (GraphQL/OpenAPI) with patterns |
|
||||
Reference in New Issue
Block a user