Skip to content

ApolloServer GraphQL Playground not necessarily turned off in production #1591

@dthyresson

Description

@dthyresson

While

https://github.com/redwoodjs/redwood/blob/895c2d09552e30138a9da09d447caea353f2a5ca/packages/api/src/functions/graphql.ts#L90

does turn off the playground if in dev mode, because it relies on process.env.NODE_ENV

process.env.NODE_ENV !== 'production'

and this may not be set in Netlify, the GraphQL playground could be exposed.

export const createGraphQLHandler = ({
  context,
  getCurrentUser,
  onException,
  cors,
  onHealthCheck,
  ...options
}: GraphQLHandlerOptions = {}) => {
  const isDevEnv = process.env.NODE_ENV !== 'production'
  const handler = new ApolloServer({
    // Turn off playground, introspection and debug in production.
    debug: isDevEnv,
    introspection: isDevEnv,
    playground: isDevEnv,

How to fix?

  • make sure process.env.NODE_ENV is set? (edit: nope ...)
  • be explicit and have GRAPHQL_PLAYGROUND_ENABLED env set only in dev and check that value for enabling the playground

Notes:

https://community.netlify.com/t/node-env-is-undefined-in-lambda-functions-no-matter-what-i-do/20667/2

Issue at hand is the Netlify Build vs Runtime environment. You will have to explicitly set NODE_ENV as a Netlify environment variable in their admin UI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions