How to disable graphql playground?

112 views Asked by At

My angular application is configured with graphql which by default enabled with playground, how to disable it? following is my 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"
  }

and 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 module added with playground set to false but it is still enabled 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 {}
1

There are 1 answers

4
Jay McDoniel On BEST ANSWER

In the GraphQlModule's options, set playground: false.

app.module.ts

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