0

So I have this codegen.yml

overwrite: true
schema: 
    - ${REACT_APP_GRAPHQL_URL}:
        headers: 
            'x-hasura-admin-secret': ${REACT_APP_GRAPHQL_ADMIN_SECRET}
documents: "./src/**/*.{ts,tsx}"
generates:
    src/generated/graphql.tsx:
        plugins:
            - "typescript"
            - "typescript-operations"
            - "typescript-react-apollo"
        config:
            withHooks: true

My .env looks like this:

REACT_APP_GRAPHQL_URL=https://somesite.com/graphql
REACT_APP_GRAPHQL_ADMIN_SECRET=abcde1234

but it failed everytime I run codegen npm run codegen and npm run codegen -r dotenv/config. I've tried changing up the quote marks, spaces etc but it still doesn't work. When I replace the environment variable with the URI and admin-secret, it runs fine. What did I do wrong?

Aituusi
  • 123
  • 2
  • 8

1 Answers1

0

Not the best solution but it's worked for me

Add your variebles before calling script like:

REACT_APP_GRAPHQL_URL=$(grep REACT_APP_GRAPHQL_URL .env | cut -d '=' -f2)

so script should looks like

"scripts": {
    "graphql-codegen": "REACT_APP_GRAPHQL_URL=$(grep REACT_APP_GRAPHQL_URL .env | cut -d '=' -f2) REACT_APP_GRAPHQL_ADMIN_SECRET=$(grep REACT_APP_GRAPHQL_ADMIN_SECRET .env | cut -d '=' -f2) graphql-code-generator --config ./codegen.yml",
  },

Then just run

    npm run graphql-codegen