ApolloServerPluginLandingPageLocalDefault from @apollo/server is not compatible with NestJS GraphQLModule config

796 Views Asked by At

I am migrating my NestJS application from Apollo v3 to Apollo v4, but I encountered a problem. Following the migration guide here I modified the import statement for the local landing page:

import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path';
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'; //was 'apollo-server-core'
import { DenunciaDetallesModule } from './registry/denuncia-detalles/denuncia-detalles.module';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
      sortSchema: true,
      driver: ApolloDriver,
      playground: false,
      plugins: [ApolloServerPluginLandingPageLocalDefault()],
    }),
    DenunciaDetallesModule,
  ],
})
export class AppModule {}

However, when running the API, I get the following error:

src/app.module.ts:15:17 - error TS2322: Type 'ApolloServerPlugin<BaseContext>' is not assignable to type 'PluginDefinition'.
Types of property 'serverWillStart' are incompatible.
      Type '(service: GraphQLServerContext) => Promise<void | GraphQLServerListener>' is not assignable to type '(service: GraphQLServiceContext) => Promise<void | GraphQLServerListener>'.
        Types of parameters 'service' and 'service' are incompatible.
          Type 'GraphQLServiceContext' is missing the following properties from type 'GraphQLServerContext': cache, startedInBackground

15       plugins: [ApolloServerPluginLandingPageLocalDefault()],

I could just switch back to apollo-server-core, but I don't understand why the types are not compatible if I updated all packages and made a clean install. Here are my dependencies:

"dependencies": {
    "@apollo/server": "^4.7.4",
    "@nestjs/apollo": "^10.1.7",
    "@nestjs/class-validator": "^0.13.4",
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/graphql": "^10.1.7",
    "@nestjs/platform-express": "^9.0.0",
    "@nestjs/swagger": "^6.1.3",
    "@types/mssql": "^8.1.1",
    "apollo-server-core": "^3.12.0",
    "apollo-server-express": "^3.12.0",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.13.2",
    "graphql": "^16.6.0",
    "joi": "^17.7.0",
    "mssql": "^9.1.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "typeorm": "^0.3.11"
  },
1

There are 1 best solutions below

0
On

@nestjs/apollo@^10 is comptible with apollo 3. To use apollo 4 you need to use @nestjs/apollo@^11