【问题标题】:RelayFindGraphQLTags failing to compile even though requirements are satisfied即使满足要求,RelayFindGraphQLTags 也无法编译
【发布时间】:2021-11-18 02:19:37
【问题描述】:

我正在尝试编译 Relay,但它没有将我的 graphql 查询识别为有效。

示例查询:

const testQuery = graphql`query CustomersQuery {
   customers(first: 20) {
     nodes {
       id
       name
     }
   }
 }`

该项目在 CRA 2.0 上使用 Typescript。

构建脚本如下:

"relay": "relay-compiler --src ./src --schema ./schema.graphql --language typescript --extensions ts tsx js jsx"

这是我收到的错误:

Parse error: Error: RelayFindGraphQLTags: Operation names in graphql tags must be prefixed with the module name and end in "Mutation", "Query", or "Subscription". Got `CustomersQuery` in module `Main`.

有人知道为什么会这样吗?感觉像个bug。

【问题讨论】:

    标签: reactjs graphql relay


    【解决方案1】:

    找到答案here。基本上说您的查询名称必须是您的文件名+“查询”。因此,对于 App.tsx,查询的名称必须是“AppQuery”。

    请注意,查询的名称必须是 Query。因此查询 clientQuery { ... } 仅在查询位于名为 client.js 的文件中时才有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-21
      • 2014-08-20
      • 1970-01-01
      • 2021-03-04
      • 2018-01-02
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      相关资源
      最近更新 更多