【问题标题】:GraphQL Apollo types generation on React NativeReact Native 上的 GraphQL Apollo 类型生成
【发布时间】:2021-08-29 07:55:18
【问题描述】:

我正在使用

  • Neo4J 4.2
  • 阿波罗服务器
  • GraphQL & @neo4j/graphql(从 schema.graphql 生成 Neo4J 类型)
  • Expo React Native + Apollo 客户端
  • 打字稿

我想通过关注this tutorial 为 GraphQL 查询生成 TS 类型。

By default apollo-cli 会在 ./src 文件夹中查找,但在 React Native 中我没有这样的文件夹,它都在根目录中。因此,当我尝试像这样为 apollo 客户端更改 includes 配置时:

<root>/apollo.config.js

module.exports = {
  client: {
    includes: ['**/*.{ts,tsx}'],
  },
};

跑步

> apollo codegen:generate --endpoint=http://localhost:4001/ --target=typescript --tagName=gql

导致:

Error: Error initializing Apollo GraphQL project "Unnamed Project": Error: Error in "Loading queries for Unnamed Project": Error: ️️There are multiple definitions for the `OpName` operation. Please rename or remove all operations with the duplicated name before continuing.

【问题讨论】:

    标签: typescript react-native neo4j graphql apollo


    【解决方案1】:

    几个小时后,我使用以下配置解决了这个问题:

    module.exports = {
      client: {
        includes: ['graphql/**/*.ts'],
      },
    };
    

    我的猜测是 apollo-cli 在所有 React Native 生成​​的代码中发现了一些 gql 标签。

    附:我尝试使用特定的关键字,以便 Google 将这个结果显示给遇到相同问题并被卡住的人。

    【讨论】:

      猜你喜欢
      • 2020-03-22
      • 2020-12-21
      • 2021-07-08
      • 2019-11-13
      • 2021-02-22
      • 1970-01-01
      • 2017-10-25
      • 2020-02-27
      • 2018-02-01
      相关资源
      最近更新 更多