apollographql / apollo

:rocket: Open source tools for GraphQL. Central repo for discussion.
https://www.apollographql.com
MIT License
2.61k stars 427 forks source link

Ability to configure schema registration without env vars #1216

Open ThomWright opened 3 years ago

ThomWright commented 3 years ago

Looking at these docs I see no way to configure some basic properties of schema registration using function arguments rather than environment variables.

If there is a way, could someone point me towards it please? If not, could it be added? Either way, could it be added to the docs?

It seems that ApolloServerPluginSchemaReporting would be the place to include (some of?) these, but I see nothing there.

Thank you.

Rant about libraries defining environment variables I see no reason why these should be environment variables. Apollo is a library. I would like to see the configuration I pass to it in my code as function arguments, just like any other library I use. I do not want my libraries relying on global variables. As the application developer, I should get to decide what environment variables my application takes. It should not be determined by the libraries it uses.

If you're using the dotenv library, you can add the API key to the .env file in your project's root directory, like so:

This, from the linked docs, I think might encourage bad practice. Many developers might see this then add a .env file to their repo and check it in, including their secret API key. I hope I don't need to explain why this is a bad idea! In general I don't think environment variables should live in the application source code repository. See The Twelve-Factor App.

StephenBarlow commented 3 years ago

Hello, thanks for reporting! You can indeed provide these values to the ApolloServer constructor via the apollo option.

You've pointed out some definite omissions in the docs (including a warning about git-ignoring .env, which we try to add anywhere we include a mention of it), so I'll leave this open until I resolve those.