代码生成故障排除
错误
类型名冲突
示例错误输出
类型名冲突错误输出
TypeNameConflict - Field 'values' conflicts with field 'value' in operation/fragment `ConflictingQuery`. Recommend using a field alias for one of these fields to resolve this conflict.
如果你收到这个错误,你有一个操作 或 片段,由于代码生成中的单复数化处理方式,导致了同名多种类型的产生。以下是一个示例模式和 查询 定义:
示例模式
type Query {user: User}type User {containers: [Container]}type Container {value: Valuevalues: [Value]}type Value {propertyA: String!propertyB: String!propertyC: String!propertyD: String!}
冲突查询
query ConflictingQuery {user {containers {value {propertyApropertyBpropertyCpropertyD}values {propertyApropertyC}}}}
如果你使用这些进行代码生成,你会得到TypeNameConflict
错误,因为你的查询生成的代码会看起来像这样:

如错误提示所说,建议的解决方案是使用一个 字段 别名,因此更新查询为:
冲突查询
query ConflictingQuery {user {containers {value {propertyApropertyBpropertyCpropertyD}valueAlias: values {propertyApropertyC}}}}
如果您运行带有更新 查询 的代码生成,您将不再看到错误,生成的代码将如下所示:
