Apollo iOS Client代码生成报错:Cannot query field问题咨询
问题分析:apollo-ios-cli generate 报错 "Cannot query field 'getAuthServiceHealth' on type 'undefined'"
问题场景
通过CocoaPods集成Apollo iOS,执行apollo-ios-cli generate命令时触发错误,错误信息如下:
Error: Cannot query field "getAuthServiceHealth" on type "undefined"
./../NetworkInterface/GraphQL/QueriesList.graphql:2:2
1 | query Health {
2 | getAuthServiceHealth{
| ^
3 | status
相关文件内容:
查询文件(Queries.graphql)
query Health { getAuthServiceHealth{ status service } }
Schema片段
{ "__schema": { "queryType": { "name": "Query" }, "mutationType": null, "subscriptionType": null, "types": [ { "kind": "OBJECT", "name": "Query", "description": null, "fields": [ { "name": "getAuthServiceHealth", "description": null, "args": [], "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "OBJECT", "name": "HealthResponse", "ofType": null } }, "isDeprecated": false, "deprecationReason": null },
错误原因
Schema文件加载异常
Apollo CLI无法正确读取完整的Schema定义,可能是配置文件中schemaPath指向错误,或是Schema文件本身存在语法错误(比如未闭合的JSON结构),导致CLI无法识别根Query类型,进而将查询的根类型判定为undefined。查询文件关联问题
错误提示指向的是QueriesList.graphql,但你提供的查询内容来自Queries.graphql,需确认:- 是否存在
QueriesList.graphql文件,且该文件中的查询语句是否存在语法问题(比如未正确关联根Query类型) - CLI是否同时加载了多个查询文件,其中某个文件的查询结构异常影响了整体解析
- 是否存在
Apollo配置错误
检查apollo-codegen-config.json(或自定义配置文件)中的配置项:includes是否正确包含了所有需要生成代码的查询文件schemaPath是否准确指向了包含完整Query类型定义的Schema文件(而非片段)
内容的提问来源于stack exchange,提问作者dferreira
相关产品推荐
相关产品推荐

