Catch the highlights of GraphQLConf 2023!Click for recordings.Or check out our recap blog post.
v4
Integrations
NestJS
⚠️
This is the documentation for the old GraphQL Yoga version 4. We recommend upgrading to the latest GraphQL Yoga version 5.

Migrate to GraphQL Yoga v5

Integration with NestJS

Nest (Nest JS) (opens in a new tab) 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).

💡

For the setup of a new Nest project, please make sure to read the Nest GraphQL documentation (opens in a new tab).

Standalone

Install

npm i @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 {}

Develop GraphQL

This is just a HTTP transport driver; meaning, everything else should work as showcased in NestJS documentation (opens in a new tab).

Apollo 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

Create Application Module

import { YogaFederationDriver, YogaFederationDriverConfig } from '@graphql-yoga/nestjs-federation'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'
 
@Module({
  imports: [
    GraphQLModule.forRoot<YogaFederationDriverConfig>({
      driver: YogaFederationDriver,
      typePaths: ['**/*.graphql']
    })
  ]
})
export class AppModule {}

Develop GraphQL

This is just a federation and gateway driver; meaning, everything else should work as showcased in NestJS federation documentation (opens in a new tab).

💡

A complete example, with full Apollo Federation Subgraph Compatibility, is available in the repository (opens in a new tab).