Open marktani opened 6 years ago
Also interested in this. It seems that dotenv
has been adopted in Prisma, but what about graphcool-framework?
For future googlers, I've found a solution I wrote up here: https://www.graph.cool/forum/t/how-to-use-environment-variables/1964/7?u=jesstelford
I've figured out how to use a
.env
file along with thegraphcool.yml
file for some sweet env support:
- Create a
.env
file in the root of your project, and add some variables:TWITTER_KEY=XXXXXXX TWITTER_SECRET=XXXXXXXX
- Edit your
graphcool.yml
to add those env vars:functions: twitterAuth: handler: code: src: ./src/authentication/twitter.ts # Define environment variables to be used in function environment: TWITTER_KEY: ${env:TWITTER_KEY} TWITTER_SECRET: ${env:TWITTER_SECRET} type: resolver schema: ./src/authentication/twitter.graphql
- Install the
dotenv
npm module:yarn add --dev dotenv
/npm install --save-dev dotenv
- Load the
.env
when you rungraphcool deploy
:cd graphcool-dir node -r dotenv/config $(which graphcool) deploy dotenv_config_path=../.env
- In your code, reference the env vars with
process.env.TWITTER_KEY
Issue by kbrandwijk Saturday Oct 14, 2017 at 10:57 GMT Originally opened as https://github.com/graphcool/prisma/issues/810
What feature are you missing? An easy way to work with stage-specific environment variables.
How could this feature look like in detail? Tradeoffs? I proposed the
dotenv
standard a while ago. That idea was discarded because the .graphcoolrc file structure wasn't a good fit for it. With the new structure, I think it's feasible to reconsider that decision.If I have different secret environment variables for different stages, I can put them in the project file in the latest alpha, which exposes them when using git. So that's not an option. I can also use something like
direnv
, but that doesn't work well on Windows, and also, I don't have a seperate folder for each stage, so that approach doesn't work well either.Unless there's another way I'm missing, I still don't have a proper solution for stage-specific env vars.