为啥 apollo client:codegen 不生成类型?
Posted
技术标签:
【中文标题】为啥 apollo client:codegen 不生成类型?【英文标题】:Why apollo client:codegen is not generate types?为什么 apollo client:codegen 不生成类型? 【发布时间】:2020-06-24 01:58:19 【问题描述】:我正在尝试获取我的 Apollo 服务器中定义的类型
首先,有效地下载架构:
apollo client:download-schema src/code/queries/schemas/schema.json --endpoint http://localhost:4000/
该命令生成以下 .json,出于演示目的对其进行了缩减。
"__schema":
"queryType":
"name": "Query"
,
"mutationType":
"name": "Mutation"
,
"subscriptionType": null,
"types": [
"kind": "OBJECT",
"name": "Query",
"description": null,
"fields": [
"name": "UserInformation",
"description": null,
"args": [],
"type":
"kind": "OBJECT",
"name": "User",
"ofType": null
,
"isDeprecated": false,
"deprecationReason": null
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
,
"kind": "OBJECT",
"name": "User",
"description": null,
"fields": [
"name": "firstName",
"description": null,
"args": [],
"type":
"kind": "SCALAR",
"name": "String",
"ofType": null
,
"isDeprecated": false,
"deprecationReason": null
,
"name": "secondName",
"description": null,
"args": [],
"type":
"kind": "SCALAR",
"name": "String",
"ofType": null..........
然后将类型生成为打字稿但没有成功:
apollo client:codegen --target typescript --localSchemaFile src/code/queries/schemas/schema.json --outputFlat src/code/queries/generated
globalTypes.ts 生成为空(仅 cmets)..
【问题讨论】:
【参考方案1】:您需要包含--includes
选项以指示哪些文件包含要为其生成类型的实际查询。来自docs:
--includes=includes 用于搜索 GraphQL 操作的文件全局。这应该用于查找查询和任何客户端架构扩展
【讨论】:
以上是关于为啥 apollo client:codegen 不生成类型?的主要内容,如果未能解决你的问题,请参考以下文章
为啥 Apollo/GraphQL 返回一个不可扩展的对象?
(GraphQL) - 为啥 Apollo 先检查缓存,然后再做其他事情?
我的突变适用于 Amplify,但不适用于 Apollo。为啥?