Search code examples
apollo-server

disable graphiql on production


How can I disable graphiql on production but still able to access it on development?

With express-graphql we can do something like

app.use('/graphql', graphqlHTTP({
  schema: MySessionAwareGraphQLSchema,
  graphiql: process.env.NODE_ENV === 'development',
}));

With apollo server, my setup is

import {graphqlExpress, graphiqlExpress} from 'graphql-server-express'

const app = new Express()

app
  .all('/graphql', bodyParser.json())
  .all('/graphql', graphqlExpress({
      schema
  )
  .all('/graphiql', graphiqlExpress({
      endpointURL: 'http://localhost/graphql'
    })
  )

and I can't find a way to pass to NODE_ENV to enable/disable graphiql.


Solution

  • Do you mean to enable graphiql on development only and disable it on production. If so just exclude the /graphiql handler

    if (process.env.NODE_ENV === 'development') {
      app.all(
        '/graphiql',
        graphiqlExpress({
          endpointURL: '/graphql',
        }),
      );
    }