NodeJS 如何禁用graphql playground?

g9icjywg  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(147)

我的angular应用配置了graphql,graphql在playground中默认开启,如何关闭graphql?下面是我的package.json

"dependencies": {
    "@nestjs/common": "^7.0.8",
    "@nestjs/core": "^7.0.8",
    "@nestjs/graphql": "^7.3.4",
    "@nestjs/microservices": "^7.0.8",
    "class-transformer": "^0.2.3",
    "class-validator": "^0.12.2",
    "graphql": "^14.0.0",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^6.0.0"
  }

字符串
Dockerfile**

FROM node:16
RUN mkdir -p /testappservice/app

COPY dist/apps/testappservice-container testappservice/app
COPY apps/testappservice/build/docker/package.json testappservice

WORKDIR /testappservice
RUN yarn install

ENV PORT 80
ENV NODE_TLS_REJECT_UNAUTHORIZED 0
ENV NODE_ENV=production
CMD ["node", "app/index.js"]


添加了app模块,将playground设置为false,但它仍处于启用状态app.module.ts

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      playground:false,
      typePaths: ['./**/*.graphql'],
      definitions: {
        path: join(process.cwd(), './apps/testappservice/src/graphql.schema.ts'),
      },
      dataSources: () => {
        return {
          xyzAPI: new XYZAPI(),
          abcAPI: new ABCAPI(),
        };
      },
      context: ({ req }) => ({ req }),
    }),
    ABCModule,
    XYZModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

kmb7vmvb

kmb7vmvb1#

GraphQlModule的选项中,设置playground: false
app.module.ts

@Module({
  imports: [
    GraphQLModule.forRoot({
      playground: process.env.NODE_ENV === 'development',
      ...otherOptions
    }),
    ...otherImports,
  ],
  ...otherModuleMetadata
})
export class AppModule {}

字符串

相关问题