NestJS GraphQL

The official GraphQL module for building type-safe GraphQL APIs in NestJS

Library
npm
v13.4.5
1,548stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
94/100Excellent
Development Activity100
Maintenance96
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture87
Code Quality85
Innovation78
Learning Curve72

@nestjs/graphql is the official integration between NestJS and GraphQL, letting you define resolvers, types, and schemas using the same decorator-driven, dependency-injection-friendly patterns NestJS uses for REST controllers. It supports both code-first (TypeScript classes + decorators generate the schema) and schema-first (SDL files generate TypeScript types) development styles.

The package is driver-agnostic: it plugs into either Apollo Server (@nestjs/apollo) or Mercurius (@nestjs/mercurius) as the underlying GraphQL execution engine, while @nestjs/graphql itself owns the schema-building, decorator, and resolver-wiring layer shared across both. This makes it the entry point most NestJS teams reach for first when adding GraphQL to an application, with the driver package chosen separately based on performance or ecosystem needs.

What You Get

  • @Resolver, @Query, @Mutation, @Subscription, and @Field decorators that wire GraphQL operations to NestJS providers and DI
  • Code-first schema generation from TypeScript classes, or schema-first generation of TypeScript types from .graphql SDL files
  • A GraphQLModule.forRoot()/forRootAsync() entry point that plugs into either the Apollo or Mercurius driver package
  • Built-in support for Apollo Federation for composing a distributed/federated GraphQL schema across services
  • Subscription support for real-time GraphQL over WebSockets
  • A CLI plugin that reduces decorator boilerplate by inferring GraphQL types from TypeScript types at build time

Common Use Cases

  • Adding a GraphQL API layer to an existing NestJS REST application without abandoning its module/DI structure
  • Building federated GraphQL architectures where multiple NestJS services contribute to one composed schema via Apollo Federation
  • Schema-first teams that want SDL as the source of truth with generated TypeScript types for resolver safety
  • Real-time GraphQL subscriptions layered onto an existing NestJS service

Under The Hood

Architecture — The repo is a Lerna-managed monorepo (packages/graphql, packages/apollo, packages/mercurius) where @nestjs/graphql owns schema construction and decorator metadata (lib/graphql-schema.builder.ts, lib/graphql.factory.ts, lib/decorators/, lib/type-factories/) while the driver packages (@nestjs/apollo, @nestjs/mercurius) implement a common driver interface that plugs the built schema into the chosen GraphQL server engine. GraphQLModule.forRoot() is the composition root: it accepts a driver instance, builds the schema from decorated resolver classes (code-first) or loaded SDL (schema-first) via lib/schema-builder/, and registers it with NestJS’s module/DI system so resolvers receive constructor-injected services exactly like REST controllers do.

Tech Stack — Built on TypeScript with graphql-js and @graphql-tools for schema construction/merging, type-graphql-inspired decorator metadata for the code-first path, and reflect-metadata for runtime type introspection. The monorepo uses Yarn workspaces and Lerna for versioning across the three published packages, with renovate.json automating dependency updates (visible as the top contributor by commit count in this repo’s history).

Code Quality — Extensive .spec.ts unit test coverage (41+ spec files) across decorators, schema builders, and type factories, reflecting the maturity expected of a first-party NestJS package maintained by the core team. The federation and subscription code paths in particular carry dedicated test suites given their complexity.

API Design — The decorator API (@Resolver(), @Query(), @Mutation(), @Args()) deliberately mirrors NestJS’s @Controller()/@Get()/@Param() REST conventions, so developers already familiar with NestJS controllers have almost no new mental model to learn for GraphQL resolvers. The code-first/schema-first duality is the one added decision point: code-first minimizes SDL authoring but requires decorator discipline, while schema-first requires a build step to regenerate types from .graphql files. The CLI plugin (which infers types from TypeScript signatures) further reduces code-first boilerplate once configured.

Used by 6 apps in this directory

TypeScript
88%
Other

AFFiNE

Productivity · Project Management · Note Taking

71,668

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript88%
Updated today
TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,010

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
61
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 1 months ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

8,938

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
86
Repo Health
67
Technical
69
Dependency
Built with
TypeScript95%
Updated today
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,055

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
66
Dependency
Built with
TypeScript67%
Vue23%
Updated 3 days ago
TypeScript
96%
Apache 2.0

Pezzo

AI Development · Monitoring

3,265

Open-source LLMOps platform for prompt management, AI observability, intelligent caching, and real-time cost tracking across LLM providers.

View details
59
Repo Health
75
Technical
67
Dependency
Built with
TypeScript96%
Updated 3 weeks ago
TypeScript
79%
Other

twenty

CRM

55,120

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
67
Dependency
Built with
TypeScript79%
MDX17%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search