GraphQL vs tRPC: Schema-First or TypeScript?
GraphQL is a language-agnostic, schema-based query layer; tRPC gives end-to-end TypeScript type safety between client and server with no schema or codegen.
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. GraphQL favors flexibility and interoperability; tRPC favors zero-friction type safety in TS monorepos.
| GraphQL | tRPC | |
|---|---|---|
| Languages | Any | TypeScript only |
| Schema | Explicit, typed | Inferred from code |
| Codegen | Often needed | None |
| Clients | Polyglot, public | TS full-stack |
| Best for | Public/varied clients | TS monorepos |
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.
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.
# 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"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.
The verdict
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.