【问题标题】:Relay compiler throws syntax error: Unexpected "$" when running in Github ActionRelay 编译器抛出语法错误:在 Github Action 中运行时出现 Unexpected "$"
【发布时间】:2020-12-14 13:25:04
【问题描述】:

我正在使用 Relay(和 Hasura),因此需要使用 relay-compiler 提前编译我的代码。我可以在本地机器上编译代码,但是在 Github Actions 中总是失败。

这是我的yml 文件中中断的部分:

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

这是我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",

它失败并出现错误:

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

我已验证 schema 已正确下载,并且 schema 和 src 文件夹的路径正确。

是否需要传递特定的配置或参数才能使其在 CI 环境中工作?


更新

经过更多测试,我发现从 get-graphql-schema 下载的文件不知何故不正确。如果我提交架构并使用它而不是下载它,则问题不存在。

我知道上传graphql.schema 文件是不好的做法,是这样吗?如果是这样,是否需要特殊参数或设置才能使架构文件在 Github Actions 中正常工作?

【问题讨论】:

    标签: graphql github-actions relay


    【解决方案1】:

    我设法发现在运行 get-graphql-schema 它的 Github Actions 时,它将以下行添加为文件的第一行。我可以通过一个额外的脚本来删除它。

    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
    }
    ...
    

    我不确定为什么在 github 操作中运行此命令会复制第一行。

    【讨论】:

      猜你喜欢
      • 2015-09-02
      • 1970-01-01
      • 2019-10-10
      • 2020-04-27
      • 2012-07-03
      • 2016-06-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      相关资源
      最近更新 更多