🦅 NestJS Intermediate

What is NestJS GraphQL module?

Answer

NestJS has first-class GraphQL support via @nestjs/graphql which wraps Apollo Server or Mercurius. Two approaches: Code-first: define the schema using TypeScript classes with decorators (@ObjectType(), @Field(), @Resolver(), @Query(), @Mutation()) — the schema is auto-generated. Schema-first: write a .graphql SDL file and NestJS generates TypeScript interfaces from it. The code-first approach is preferred for TypeScript projects as it avoids schema/type duplication. DataLoader integration handles N+1 query problems. Subscriptions are supported over WebSocket. Guards, Interceptors, and Pipes work in GraphQL context when using ExecutionContext.switchToHttp()-aware alternatives.