question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApolloServer GraphQL Playground not necessarily turned off in production

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Tobbecommented, Jan 17, 2021

How about we change to const isDevEnv = process.env.NODE_ENV === 'development'?

0reactions
Tobbecommented, Jan 17, 2021

How about we change to const isDevEnv = process.env.NODE_ENV === 'development'?

Actually this wouldn’t work yet, because NODE_ENV is undefined on localhost too. But I’ve fixed that in https://github.com/redwoodjs/redwood/pull/1653 So when that lands I can PR this fix too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why You Should Disable GraphQL Introspection In Production
In this post, we'll discuss why we believe you should disable GraphQL introspection in production, how to do it, and present a way...
Read more >
In production with apollo-server-express 2.0.4 Playground is ...
This behavior can be over-ridden when you set the playground option in config. In 2.0.0, the graphql playground could be enabled when NODE_ENV= ......
Read more >
Is there any option to disable playground when in production ...
In Apollo Server 3, Playground is disabled by default. In fact, they rolled their own "playground" because Playground has been retired.
Read more >
GraphQL Overview - Keystone 6 Documentation
When NODE_ENV=production is not set, by default Keystone serves the GraphQL playground, an in-browser GraphQL IDE for debugging and exploring the API and ......
Read more >
GraphQL Server Tutorial with Apollo Server and Express
In this chapter, you will implement server-side architecture using GraphQL and Apollo Server. The GraphQL query language is implemented as a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found