Nest.js 错误:只有一个插件可以实现 renderLandingPage

yut*_*uro 1 typescript graphql nestjs prisma

我正在使用 Nest.js graphql prisma。
当我运行 npm run start:dev 命令时,出现以下错误。

错误

/node_modules/apollo-server-core/src/ApolloServer.ts:471 throw Error('只有一个插件可以实现 renderLandingPage。'); ^ 错误:只有一个插件可以实现 renderLandingPage。

app.module.ts
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core';
import { DonationsModule } from './donations/donations.module';
import { ApolloDriverConfig, ApolloDriver } from '@nestjs/apollo';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      plugins: [ApolloServerPluginLandingPageLocalDefault()],
      typePaths: ['./**/*.graphql'],
    }),
    DonationsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Run Code Online (Sandbox Code Playgroud)

小智 5

根据NestJs 文档

要使用 Apollo Sandbox 而不是 graphql-playground 作为 GraphQL IDE 进行本地开发,请使用以下配置:

因此,您必须在代码中插入.forRoot({})以下元素:playground: false,

所以你的代码将是:

app.module.ts
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core';
import { DonationsModule } from './donations/donations.module';
import { ApolloDriverConfig, ApolloDriver } from '@nestjs/apollo';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      playground: false, // this line is the only change in your code
      plugins: [ApolloServerPluginLandingPageLocalDefault()],
      typePaths: ['./**/*.graphql'],
    }),
    DonationsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)