# GraphQL vs tRPC: スキーマファーストかTypeScriptか?

> GraphQL vs tRPC: 言語非依存の型付きクエリレイヤーと、スキーマ不要のend-to-endなTypeScript型安全性。ユースケースとCIへの適合性を率直に比較。

Source: https://latchkey.dev/ja/learn/tool-comparisons/graphql-vs-trpc  
Updated: 2026-06-26

GraphQLは言語非依存でスキーマベースのクエリレイヤーであり、tRPCはスキーマやcodegenなしでクライアントとサーバー間にend-to-endのTypeScript型安全性をもたらします。

GraphQLは任意のクライアントや言語が利用できる型付きスキーマを定義し、柔軟なクエリと豊富なエコシステムを備え、パブリックAPIやポリグロットなクライアントに適しています。tRPCはTypeScript専用で、サーバーのprocedureが完全に型付けされたクライアント呼び出しとしてインポートされ、フルスタックTSアプリからスキーマとcodegenを排除しますが、TSの世界の中に限られます。GraphQLは柔軟性と相互運用性を、tRPCはTSのmonorepoでの摩擦のない型安全性を重視します。

## Comparison

|  | GraphQL | tRPC |
| --- | --- | --- |
| 言語 | 任意 | TypeScriptのみ |
| スキーマ | 明示的、型付き | コードから推論 |
| Codegen | しばしば必要 | なし |
| クライアント | ポリグロット、パブリック | TSフルスタック |
| 最適な用途 | パブリック/多様なクライアント | TSのmonorepo |

## ユースケースと型安全性

GraphQLは形式的な契約を必要とするパブリックAPI、モバイル、ポリグロットなコンシューマーに適しています。tRPCはクライアントとサーバーが型を直接共有するフルスタックTypeScriptアプリ(多くはNext.js)に適しており、スキーマなしで即座にend-to-endの安全性をもたらしますが、TS以外や外部のコンシューマーを同じようにきれいに扱うことはできません。

## CIにおいて

GraphQLのパイプラインはスキーマを検証しクライアントのcodegenを実行します。tRPCはTypeScriptコンパイラに依存するため、type-checkが主なgateになります。どちらもマネージドrunnerで動作し、より高速なrunnerはtype-checkとcodegenのステップを短縮します。

## Decide with your own numbers, not a feature table

Feature comparisons age badly and rarely decide anything, because both tools in a mature category can do the job. What differs is how each behaves on your repository, and that takes one afternoon to measure.

```Terminal
# time a cold install with each candidate, cache cleared
hyperfine --prepare "rm -rf node_modules" --warmup 1 \
  "<tool-a> install" "<tool-b> install"

# and the thing CI actually pays for: a cold run with no local cache
docker run --rm -v "$(pwd):/w" -w /w node:22 sh -c "<tool> install"
```

> Measure the cold path. Warm local benchmarks favour whichever tool you already have cached, which is exactly the condition a CI runner never has.

## What actually changes when you switch

- Lockfile format. A switch is a one-way door for anyone still on the old tool until everyone migrates, so plan it as a single coordinated change.
- Resolution strictness. Tools differ on whether an undeclared transitive import works, and the stricter one will surface latent bugs as new failures.
- CI cache configuration. The cache path and key differ per tool; carrying over the old ones silently disables caching.
- Everyone on the team and every runner must move together. Pin the version so they cannot drift.

## 結論

形式的で柔軟な契約を必要とするパブリックAPIやポリグロットなクライアントには、GraphQLです。摩擦のないend-to-endの型安全性を望む社内のフルスタックTypeScriptアプリには、tRPCです。tRPCはTSのmonorepo内では優れており、GraphQLは外部やTS以外のコンシューマーが重要な場合の選択肢です。

## FAQ

### GraphQL vs tRPC: Schema-First or TypeScript?

GraphQL defines a typed schema any client or language can consume, with flexible queries and a rich ecosystem, suiting public APIs and polyglot clients. tRPC is TypeScript-only: server procedures are imported as fully typed client calls, eliminating schemas and codegen for full-stack TS apps, but only within the TS world.

### Use case and type safety?

GraphQL fits public APIs, mobile, and polyglot consumers needing a formal contract. tRPC fits full-stack TypeScript apps (often Next.js) where client and server share types directly, giving instant end-to-end safety without a schema, but it cannot serve non-TS or external consumers as cleanly.

### In CI?

GraphQL pipelines validate the schema and run client codegen. tRPC relies on the TypeScript compiler, so type-check is the main gate. Both run on managed runners, where faster runners shorten type-check and codegen steps.

### Which should I choose?

Public APIs or polyglot clients needing a formal, flexible contract: GraphQL. Internal full-stack TypeScript apps wanting frictionless end-to-end type safety: tRPC. tRPC is excellent inside a TS monorepo; GraphQL is the choice when external or non-TS consumers matter.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
