Nest (Nest JS) is a progressive Node.js framework for building efficient, reliable and scalable server-side applications.
Nest (Nest JS) is a progressive Node.js framework for building efficient,
reliable and scalable server-side applications.
GraphQL Yoga provides its own Nest GraphQL Driver that support building standalone GraphQL APIs and
Apollo Federation GraphQL APIs (Gateway and
Services).
Standalone
Install
npm i @nestjs/graphql @graphql-yoga/nestjs graphql-yoga graphql
bun add @nestjs/graphql @graphql-yoga/nestjs graphql-yoga graphql
Create Application Module
import { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs'import { Module } from '@nestjs/common'import { GraphQLModule } from '@nestjs/graphql'@Module({ imports: [ GraphQLModule.forRoot<YogaDriverConfig>({ driver: YogaDriver }) ]})export class AppModule {}
HTTP Adapters
The driver supports the Express (default), Fastify and Node.js (@nestjs/platform-node, Nest 12.3
and later) HTTP adapters. Pass the adapter’s platform name to the driver config to type the server
context accordingly:
import { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs'import { Module } from '@nestjs/common'import { GraphQLModule } from '@nestjs/graphql'@Module({ imports: [ GraphQLModule.forRoot<YogaDriverConfig<'node'>>({ driver: YogaDriver }) ]})export class AppModule {}
import { NestFactory } from '@nestjs/core'import { NodeAdapter } from '@nestjs/platform-node'import { AppModule } from './app.module'const app = await NestFactory.create(AppModule, new NodeAdapter())await app.listen(4000)
The same applies to YogaFederationDriver from @graphql-yoga/nestjs-federation.
Separately, we offer a @graphql-yoga/nestjs-federation driver which allows building Apollo
Federation Gateways and Services through the YogaGatewayDriver and YogaFederationDriver drivers.
Install
npm i @nestjs/graphql @graphql-yoga/nestjs-federation graphql-yoga graphql