GraphQL Interface With GqlGen
- 主要语言
- Go
- 星标
- 10.8k
- 派生
- 1.3k
- 平均合并
- 2 天 36 分钟
- 30 天内合并 PR
- 26
描述
### What happened?
I'm trying to implement the GraphQL Interface but it's not working. I'm getting following error:
```{
"errors": [
{
"message": "json: cannot unmarshal object into Go struct field Segment.segments.contents of type models.Content",
"path": [
"GetData"
]
}
],
"data": {
"GetData": null
}
}
```
### Minimal graphql.schema and models to reproduce
```
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
}
```
Here is complete code:
https://bit.ly/3VGNjus
### versions
- `go run github.com/99designs/gqlgen version`? v0.17.20
- `go version`? go version go1.19 darwin/amd64
贡献指南
调研方向
这个 issue 涉及 gqlgen 中 GraphQL 接口的 unmarshalling 错误。首先检查提供的 schema 和链接的代码,以了解 Content 接口的实现。查看生成的 models 和 resolvers,尤其是 Segment.contents 字段的处理方式。运行示例以复现错误,然后查阅 gqlgen 关于接口和联合类型的文档,了解应如何配置 unmarshalling。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- go, graphql
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100