I tried to use the environment variable in the codegen.yml. I decided to generate the codegen.yml file by using the handlebars.
yarn add handlebars
codegen-template.yml
overwrite: true
generates:
./src/generated/graphql.tsx:
schema: "{{REACT_APP_GRAPHQL_ENDPOINT}}"
documents: src/**/*.graphql
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
package.json
"scripts": {
"generate-yaml": "npx handlebars -c .env -i codegen-template.yml -o codegen.yml"
}
and run
yarn generate-yaml
Got the below error
yarn run v1.22.19
$ npx handlebars -c .env.qa -i codegen-template.yml -o codegen.yml
/Users/test/Documents/Workspace/cr/node_modules/handlebars/bin/handlebars:110
throw err;
^
Error: Unable to open template file "codegen.yml"
at /Users/test/Documents/Workspace/cr/node_modules/handlebars/dist/cjs/precompiler.js:104:25
at FSReqCallback.oncomplete (fs.js:192:21) {
description: undefined,
fileName: undefined,
lineNumber: undefined,
endLineNumber: undefined,
number: undefined
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
How to resolve this issue.