Nest

How do we leverage GraphQL Federation in NestJS v10+ for enterprise API gateways?

March 18, 2026

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

GraphQL Federation lets multiple NestJS microservices expose @key entities that a central gateway stitches together into one unified schema—perfect for enterprise API gateways handling complex domain data.​

Each subgraph service uses ApolloFederationDriver with @key(fields: "id") directives on entities, while the gateway uses ApolloGatewayDriver to compose the supergraph. NestJS v10+ makes this seamless with code-first or schema-first approaches.

Subgraph service:

Code

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloFederationDriver } from '@nestjs/apollo';
import { Directive, ObjectType, Field, ID } from '@nestjs/graphql';

@ObjectType()
@Directive('@key(fields: "id")')
class User {
  @Field(() => ID)
  id: string;

  @Field()
  name: string;
}

@Module({
  imports: [
    GraphQLModule.forRoot({
      driver: ApolloFederationDriver,
      autoSchemaFile: true,
    }),
  ],
  providers: [/* your resolvers */],
})
export class UsersModule {}
      

Gateway service:

Code

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloGatewayDriver } from '@nestjs/apollo';

@Module({
  imports: [
    GraphQLModule.forRoot({
      driver: ApolloGatewayDriver,
      gateway: {
        serviceList: [
          { name: 'users', url: 'http://users-service/graphql' },
          { name: 'products', url: 'http://products-service/graphql' },
        ],
      },
    }),
  ],
})
export class GatewayModule {}
      
Hire Now!

Need Help with Nest Development ?

Work with our skilled nest developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now

How do we leverage GraphQL Federation in NestJS v10+ for enterprise API gateways?

GraphQL Federation lets multiple NestJS microservices expose @key entities that a central gateway stitches together into one unified schema—perfect for enterprise API gateways handling complex domain data.​

Each subgraph service uses ApolloFederationDriver with @key(fields: "id") directives on entities, while the gateway uses ApolloGatewayDriver to compose the supergraph. NestJS v10+ makes this seamless with code-first or schema-first approaches.

Subgraph service:

Code

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloFederationDriver } from '@nestjs/apollo';
import { Directive, ObjectType, Field, ID } from '@nestjs/graphql';

@ObjectType()
@Directive('@key(fields: "id")')
class User {
  @Field(() => ID)
  id: string;

  @Field()
  name: string;
}

@Module({
  imports: [
    GraphQLModule.forRoot({
      driver: ApolloFederationDriver,
      autoSchemaFile: true,
    }),
  ],
  providers: [/* your resolvers */],
})
export class UsersModule {}
      

Gateway service:

Code

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloGatewayDriver } from '@nestjs/apollo';

@Module({
  imports: [
    GraphQLModule.forRoot({
      driver: ApolloGatewayDriver,
      gateway: {
        serviceList: [
          { name: 'users', url: 'http://users-service/graphql' },
          { name: 'products', url: 'http://products-service/graphql' },
        ],
      },
    }),
  ],
})
export class GatewayModule {}