typescript - React Native 上的 GraphQL Apollo 类型生成
问题描述
我在用着
- Neo4J 4.2
- 阿波罗服务器
- GraphQL & @neo4j/graphql(从 生成 Neo4J 类型
schema.graphql
) - Expo React Native + 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.
解决方案
几个小时后,我使用以下配置解决了这个问题:
module.exports = {
client: {
includes: ['graphql/**/*.ts'],
},
};
我的猜测是 apollo-cligql
在所有 React Native 生成的代码中发现了一些标签。
PS 我尝试使用特定的关键字,以便谷歌将这个结果显示给有同样问题并被卡住的人。
推荐阅读
- azure - Azure DevOps Powershell 脚本无法创建 SSL/TLS 安全通道
- java - 日历 / GregorianCalendar 等效 Javascript
- python - 类型变量错误。你们能帮我让我的代码工作吗?
- html - 悬停图像时更改背景颜色
- r - 如何将数据帧从 R 导出到 excel 并用空行分隔它们
- javascript - 使用 Axios Vue JS 访问 JSON 对象内的数组
- python - 为什么当变量变为0时while循环不会停止?(Python)
- java - 用于唯一查询的 Spring/MongoDB 多计数
- sql - 需要 SQL 从子查询生成多行
- angular - NativeScript w/ Angular 9 - ../node_modules/nativescript-ui-sidedrawer/__ivy_ngcc__/angular/side-drawer-directives.js 中的错误