graphql / vscode-graphql

MIGRATED: VSCode GraphQL extension (autocompletion, go-to definition, syntax highlighting)
https://marketplace.visualstudio.com/items?itemName=Prisma.vscode-graphql
MIT License
555 stars 71 forks source link

GraphQL Configuration not pulling in JWT from environment. #424

Closed jwstevens20 closed 2 years ago

jwstevens20 commented 2 years ago

Actual Behavior

When attempting to execute a query, I get the following response:

{
  "errors": [
    {
      "message": "The supplied JWT is invalid or expired."
    }
  ]
}

When hard-coding in the JWT all works correctly.

Expected Behavior

The JWT is pulled from the environment variable.

Steps to Reproduce the Problem Or Description

Specifications

// graphql.config.js
module.exports = {
  projects: {
    live: {
      schema: 'http://localhost:8020/graphql',
      extensions: {
        endpoints: {
          default: {
            url: 'http://localhost:8020/graphql',
            headers: {
              Authorization: `${process.env.GRAPHQL_API_TOKEN}`
            }
          }
        }
      }
    }
  }
};
lucagoslar commented 2 years ago

Your issue might be similar to issue #284. @RKings solved it by requiring dotenv and pointing to the projects .env file.

// graphql.config.js
require('dotenv').config({ path: __dirname + '/.env', });
acao commented 2 years ago

Thank you @lucagoslar !

jwstevens20 commented 2 years ago

Worked perfectly. Thank you, @lucagoslar!!