Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In production with apollo-server-express 2.0.4 Playground is visible, with 2.0.0 is not. #1571

Closed
frederikhors opened this issue Aug 25, 2018 · 11 comments
Labels
🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository.

Comments

@frederikhors
Copy link

frederikhors commented Aug 25, 2018

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?

@ghost ghost added the 🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository. label Aug 25, 2018
@frederikhors
Copy link
Author

cc @nderscore @evans

@nderscore
Copy link
Contributor

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
});

@frederikhors
Copy link
Author

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?

@nderscore
Copy link
Contributor

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

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.

@frederikhors
Copy link
Author

@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?

@nderscore
Copy link
Contributor

Confirmed the issue. Sorry for the confusion.

playground: PlaygroundConfig = {},

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

@frederikhors
Copy link
Author

Is there a test for this?

@tsvetann
Copy link

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

@tsvetann
Copy link

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

@kachkaev
Copy link
Contributor

kachkaev commented Oct 5, 2018

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

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

@abernix
Copy link
Member

abernix commented Jul 5, 2019

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🌹 has-reproduction ❤ Has a reproduction in Glitch, CodeSandbox or Git repository.
Projects
None yet
Development

No branches or pull requests

5 participants