首页 > 解决方案 > React Native 上的 GraphQL Apollo 类型生成

问题描述

我在用着

我想按照本教程为 GraphQL 查询生成 TS 类型。

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

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

标签: typescriptreact-nativeneo4jgraphqlapollo

解决方案


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

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

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

PS 我尝试使用特定的关键字,以便谷歌将这个结果显示给有同样问题并被卡住的人。


推荐阅读