Apollo-server: In production with apollo-server-express 2.0.4 Playground is visible, with 2.0.0 is not.

Created on 25 Aug 2018  路  11Comments  路  Source: apollographql/apollo-server

REPRODUCTION HERE: https://brainy-spaghetti.glitch.me

With "apollo-server-express": "2.0.4" and NODE_ENV=production the Playground is visible.

With "apollo-server-express": "2.0.0" and NODE_ENV=production I have this: GET query missing.

Something is wrong?

has-reproduction 馃浌 playground

Most helpful comment

Confirmed the issue. Sorry for the confusion.

https://github.com/apollographql/apollo-server/blob/412be208c1b60c2f77333eec2840b64990ea7935/packages/apollo-server-core/src/playground.ts#L39

It's likely due to the default value of {} for the playground config here.

All 11 comments

cc @nderscore @evans

The default behavior of apollo-server's integrated graphql-playground is for it to be disabled (along with introspection queries) when NODE_ENV=production.

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=production if you explicitly set the playground option to true, but provided no way to enable the playground with a custom config object.

In 2.0.2, this was adjusted to allow a custom config to enable the playground in production. Now, a truthy value will enable the playground, while a falsey value will disable it.


If you want to disable the playground in production while using a custom config in your local/development environment, you could do something like this:

const GRAPHQL_PLAYGROUND_CONFIG = {
  folderName: 'Foo',
  settings: {
    'editor.cursorShape': 'line',
    'editor.fontSize': 14,
    'editor.reuseHeaders': true,
    'editor.theme': 'dark'
  }
};

const server = new ApolloServer({
  playground: process.env.NODE_ENV === 'production' ? false : GRAPHQL_PLAYGROUND_CONFIG,
  schema: mySchema
});

I'm not using any custom config as you can see. I think it is bad if playground is enabled by default in production. Isn't it?

I'm not familiar with glitch.me, but I figured out where I can actually find the source code. :smile:

https://glitch.com/~brainy-spaghetti

In this case, you're setting NODE_ENV to an empty string in your .env file.

To be honest, I'm not sure if/what conventions exist for how to handle an unset or empty NODE_ENV environment variable. Considering you're using express.js, I should point out that their library also defaults to development in this case.

The best practice would probably be to always explicitly set your NODE_ENV to a value rather than rely on defaults, as different libraries may use different default values.

@nderscore I'm sorry, I think glitch doesn't show the value of .env file keys to the public internet.

It is NODE_ENV=production, I can assure this to you. In fact it doesn't work the introspection.

Can you try on your PC downloading the file from glitch?

Confirmed the issue. Sorry for the confusion.

https://github.com/apollographql/apollo-server/blob/412be208c1b60c2f77333eec2840b64990ea7935/packages/apollo-server-core/src/playground.ts#L39

It's likely due to the default value of {} for the playground config here.

Is there a test for this?

I have the same problem with "apollo-server-express": "2.1.0". Older project with "apollo-server-express": "2.0.0" works just fine but with 2.1.0 I always get the playground with NODE_ENV=production

Just realised the problem is playground. So for now the workaround is playground: null

@tsvetann playground: null disables playground in development as well. My workaround:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  playground: process.env.NODE_ENV !== "production",
});

I believe this is resolved, but I realize it's been quite some time since you opened this, so if you haven't already figured this out, I'd recommend taking this question to the Apollo community on Spectrum.chat to discuss it further. Feel free to comment here as well! Thanks!

Was this page helpful?
0 / 5 - 0 ratings