NestJS and Apollo Federation: buildFederatedSchema is deprecated

Viewed 875

I am working with NestJS and Apollo Federation for a while and it seems that since last update I get

"(node:19113) DeprecationWarning: 'buildFederatedSchema' is deprecated. Use 'buildSubgraphSchema' instead."

I don't see a place where I could use buildSubgraphSchema and I didn't find anywhere from NestJS docs of Apollo Federation docs a way to remove this deprecated issue.

The full list of dependencies in my package json are

  "dependencies": {
    "@apollo/federation": "^0.33.3",
    "@apollo/subgraph": "^0.1.2",
    "@nestjs/common": "^8.0.0",
    "@nestjs/config": "^1.0.2",
    "@nestjs/core": "^8.0.0",
    "@nestjs/graphql": "^9.1.1",
    "@nestjs/mongoose": "^9.0.1",
    "@nestjs/platform-express": "^8.0.0",
    "apollo-server-express": "^3.4.0",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
    "graphql": "^15.6.1",
    "helmet": "^4.6.0",
    "joi": "^17.4.2",
    "mongoose": "^6.0.12",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },

The GraphQL module is defined in a file called graphql.module.ts with the following:

import { Module } from '@nestjs/common';
import { GraphQLFederationModule } from '@nestjs/graphql';
import { ApolloServerPluginInlineTraceDisabled } from 'apollo-server-core';

@Module({
  imports: [
    GraphQLFederationModule.forRoot({
      plugins: [ApolloServerPluginInlineTraceDisabled()],
      autoSchemaFile: true,
      playground: true,
      introspection: true,
      buildSchemaOptions: {
        dateScalarMode: 'isoDate',
      },
      context: ({ req }) => ({
        jwt: req.headers.authorization,
      }),
    }),
  ],
})
export class GraphqlModule {}

Project still runs normally with the deprecated message but I would be keen to understand how to fix it.

Thanks in advance,

SOLUTION: 2020-03-10

Based on Brando J answer, the next update of nestjs/graphql from version 9 to version 10 fix the issue

1 Answers

The cause of this warning comes from @nestjs/graphql v9 which still use "buildFederatedSchema" from @apollo/federation.

You can update to @nestjs/graphql v10 to get rid of that message. Also GraphQLFederationModule has been removed and replaced by GraphQLModule using ApolloFederationDriver.

tl;dr

  1. update @nestjs/graphql to v10
  2. read this docs to adjust your code to new version https://docs.nestjs.com/graphql/migration-guide
Related