Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use environment variables in config.yml #921

Open
yo-gen opened this issue Jan 11, 2024 · 5 comments
Open

Unable to use environment variables in config.yml #921

yo-gen opened this issue Jan 11, 2024 · 5 comments

Comments

@yo-gen
Copy link

yo-gen commented Jan 11, 2024

I am not able to figure how to pass the environment variables to config.yml file.
Already tried following variations

url: REACT_APP_API_URL/top/graphql

url: 'REACT_APP_API_URL/top/graphql'

url: 'REACT_APP_API_URL'/top/graphql

url: ${REACT_APP_API_URL}/top/graphql

url: '${REACT_APP_API_URL}/top/graphql'

None of it works :/

@newhouse
Copy link
Collaborator

@yo-gen this should be supported.

Can you provide a complete example YAML file that has this problem? And the output (if you've got it)? Perhaps there is some nesting issue or something. and can you verify that REACT_APP_API_URL is in fact in the environment where you are running this?

Perhaps you're running it in a child process or shell that does not have the process.env that you think it does.

@yo-gen
Copy link
Author

yo-gen commented Jan 12, 2024

I was running from the shell, using npx command
To make this work I had to export the env variable explicitly in the shell
Had to use below format with $ to make the config identify the env variable

url: '$REACT_APP_API_GRAPHQL_URL'

If this is the required format, maybe it would be good to have an example somewhere.

@newhouse
Copy link
Collaborator

It should actually work with either '$FOO' or '${FOO}'. Can you let me know if that is not the case?

I will add an example next time I'm in here doing some updates.

@lukasulbing
Copy link

Hey @newhouse @yo-gen,

I've also stumbled across this issue looking for a way to set environment variables in my config.yml:

spectaql:
  logoFile: public/images/logo_extended.svg
  faviconFile: public/favicon.ico
  embedFavicon: true

introspection:
  url: '${APPSYNC_GRAPHQLENDPOINT}'
  headers:
    x-api-key: '${APPSYNC_APIKEY}'

info:
  title: GraphQL API Reference
  description: >-
    ## Welcome to the party!

Apparently, as mentioned by @newhouse the environment variables are not available when I run npx spectaql config.yml in the shell. My environment variables are stored in a .env file within my Nextjs project.

Do you have any idea how I could pass these environment variables to the shell command?

The only solution I've found so far is to run a script that reads the variables, sets them in the config file, runs the command and then replaces these environment variables with placeholders again.

Thanks for any help!

@lukasulbing
Copy link

Another solution would be to export the environment variables to shell variables like so:

export APPSYNC_GRAPHQLENDPOINT=$(grep APPSYNC_GRAPHQLENDPOINT .env.local | cut -d '=' -f2)
export APPSYNC_APIKEY=$(grep APPSYNC_APIKEY .env.local | cut -d '=' -f2)
npx spectaql config.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants