kamilkisiela / graphql-config

One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
https://the-guild.dev/graphql/config
MIT License
1.16k stars 93 forks source link

Environment variables not loaded from .env file. #1319

Closed BenoitRanque closed 1 year ago

BenoitRanque commented 1 year ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug

When using environment variables in a configuration file, the environment is not loaded from a '.env` file in the root directory. If present, the defaults are used, if not, the operation fails.

To Reproduce Steps to reproduce the behavior:

Create a config file that uses environment variables to specify endpoint or header values. I was originally using .graphqlrc.yaml with templated strings as documented here.

schema:
  - ${GRAPHQL_ENDPOINT}:
documents:
  - src/**/*.{gql,graphql,ts,tsx}
# removed codegen config

Generating code using graphql codegen and type completion with the vscode graphql extension both fail. The LSP produces the following error message:

      Unable to find any GraphQL type definitions for the following pointers:

          - undefined

The environment variable(s) are set in a .env file in the root directory.

Expected behavior Environment variables should be loaded and the endpoint accessible.

Environment:

Additional context

I was able to workaround this issue by using a .graphqlrc.js file instead, and loading dotenv myself:

require('dotenv').config();
module.exports = {
  schema: [
    {
      [process.env.OPS_API_GRAPHQL_ENDPOINT]: {
      },
    },
  ],
};
ardatan commented 1 year ago

.env files are specific to dotenv library. You should load them by yourself. This is not a bug.

BenoitRanque commented 1 year ago

That makes sense, must be something else down the chain that broke. Closing this issue.