简体   繁体   中英

Relay compiler throws syntax error: Unexpected “$” when running in Github Action

I am using Relay (and Hasura) and hence are required to compile my code ahead of time using the relay-compiler . I can compile the code fine on my local machine, however it always fails when in Github Actions.

Here is the section of my yml file where is breaks:

runs-on: ubuntu-latest
# other steps
- name: Download GraphQL Schema
  run: SECRET=$SECRET ENDPOINT=$ENDPOINT yarn run get-schema
  env:
    SECRET: ${{ secrets.hasura_admin_secret }}
    ENDPOINT: ${{ secrets.graphql_endpoint }}
- name: Test Compile Relay
  run: yarn run relay <<< this fails
- name: Test build
  run: yarn run build

And here are those scripts in my package.json .

"start": "yarn run compile-css && react-scripts start",
"build": "yarn run build-compile-css && react-scripts build",
"get-schema": "yarn run get-graphql-schema -h \"x-hasura-admin-secret=$SECRET\" $ENDPOINT > schema.graphql",
"relay": "yarn run relay-compiler --schema schema.graphql --src src",

It fails with the error:

$ /home/runner/work/<company-name>/<app-name>/node_modules/.bin/relay-compiler --schema schema.graphql --src src
Writing js
ERROR:
Syntax Error: Unexpected "$".

I have verified that schema is downloaded correctly and the paths to the schema and src folder are correct.

Is there specific config or arguments I need to pass to get this working in a CI environment?


Update

After more testing, I have found that the downloaded file from get-graphql-schema is somehow not correct. The issue is not there if I commit the schema and use this instead of downloading it.

I have the understanding it is bad practice to upload graphql.schema files, is this the case? If so are there are special arguments or set up required to get schema files working correctly in Github Actions?

I have managed to find that when running the get-graphql-schema it Github Actions it add the following line as the first line of the file. I can remove this via an additional script.

schema.graphql

$ /home/runner/work/<company-name>/<app-name>/node_modules/.bin/relay-compiler --schema schema.graphql --src src
schema {
  query: query_root
  mutation: mutation_root
  subscription: subscription_root
}
...

I am unsure though why running this command in github actions will copy the first line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM