Graphql-code-generator: Support multiple .env files.

Created on 25 Aug 2020  路  3Comments  路  Source: dotansimha/graphql-code-generator

Is your feature request related to a problem? Please describe.
graphql-codegen -r dotenv/config enables environment variables within codegen.yml. For example:

schema: ${GRAPHQL_ENDPOINT}
generates:
  ...

This is great. However, it is common for frameworks to utilize multiple environment files, such as .env and .env.local (see React and Vue). Unfortunately, codegen only reads from the .env file.

Describe the solution you'd like
Support .env.local, .env.[mode], and .env.[mode].local.
For example, if GRAPHQL_ENDPOINT is defined in both .env and .env.local, the local version should be loaded into codegen.yml.

Describe alternatives you've considered
Prebuild scripts to merge all environment files into a single .env, but I'd like to avoid this.

Additional context
Thanks!

Most helpful comment

@jake-leland This worked for me..

package.json:

{
  ...
  "scripts": {
    ...
    "generate": "DOTENV_CONFIG_PATH=./.env.local graphql-codegen -r dotenv/config --config codegen.js",
    ...
  }
}

All 3 comments

You could just use dotenv -c development -- graphql-codegen

@jake-leland This worked for me..

package.json:

{
  ...
  "scripts": {
    ...
    "generate": "DOTENV_CONFIG_PATH=./.env.local graphql-codegen -r dotenv/config --config codegen.js",
    ...
  }
}

As suggested by @fubhy and @cantyjeffrey , you can either use DOTENV_CONFIG_PATH or wrap the execution of graphql-codegen with dotenv cli.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mszczepanczyk picture mszczepanczyk  路  3Comments

edorivai picture edorivai  路  3Comments

zenVentzi picture zenVentzi  路  3Comments

leebenson picture leebenson  路  3Comments

NickClark picture NickClark  路  3Comments