[英]GraphQL Interface With GqlGen
我正在尝试使用 Go GqlGen 来实现 GraphQL 接口,但它不起作用。 我收到以下错误:
"errors": [
{
"message": "json: cannot unmarshal object into Go struct field Segment.segments.contents of type models.Content",
"path": [
"GetData"
]
}
],
"data": {
"GetData": null
}
}
graphql 模式:
type Root {
id: String
title: String
segments: [Segment]
}
type Segment {
id: String
contents: [Content]
}
type Team {
name: String
}
type A implements Content {
id: String
title: String
teams: [Team]
}
type B implements Content {
id: String
title: String
score: Int
}
interface Content {
id: String
title: String
}
type Query {
GetData: Root
}
这是完整的代码:链接
谢谢您的帮助!
这是因为您的模拟数据结构与您定义的结构不匹配。
您的模拟数据在内容数组中同时获取 A 和 B 数据。 但他们的结构不同(球队与得分)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.