99designs / 99designs/gqlgen

Resolver chaining With gqlgen, mongoDB, and Apollo

未关闭
#2,695 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
10.8k
派生
1.3k
平均合并
2 天 36 分钟
30 天内合并 PR
26

描述

### What happened?
I'm unable to figure out how to chain resolvers with mongoDB.
### What did you expect?
I am expecting to be able to chain resolvers for queries with mongoDB ID's and Apollo's federation. In the Mongo data base `Application` has a resources field is an array of [ObjectID's] to `Resources` Documents. but I run into an issue when trying to resolve the application document.
```
error decoding key resources.0: cannot decode objectID into a model.Resource
```

I've tried creating a explicit resolver using
```
Application:
fields:
resources:
resolver: true
```

However this creates a separate applicationResolver upon generation that's never called when trying to do my queryResolver for Application. I feel like there should be some clean way to have this work. IE Get the Application, using the Application's resource field (a list of Resource ObjectIDs) get an array of resources. return a application with a resource struct and not a ID.


### Minimal graphql.schema and models to reproduce
schema
```
type Application @key(fields: "_id") {
_id: ID!
text: String!
resources: [Resource!]!
}

type Resource @key(fields: "_id") {
_id: ID!
text: String!
link: String!
}

type Query {
applications: [Application!]!
}
```

models generated by gqlgen (I'll ad a `bson:` field tag as well.)
```
type Application struct {
ID string `json:"_id"`
Text string `json:"text"`
Resources []*Resource `json:"resources"`
}

type Resource struct {
ID string `json:"_id"`
Text string `json:"text"`
Link string `json:"link"`
}
```
### versions
- v0.17.33
- go version go1.20.1 darwin/amd64

贡献指南

打开贡献指南

调研方向

该问题涉及 gqlgen 与 MongoDB ObjectIDs 和 Apollo Federation 的 resolver 链式调用。查看生成的 resolver 代码和 gqlgen 配置文件 (gqlgen.yml)。检查 Application 类型的 resources 字段是如何解析的,并确认 MongoDB 模型结构体具有正确的 bson 标签。该错误表明 ObjectID 与 Resource 模型之间存在解码不匹配。首先检查 Application 和 Resource 的 resolver 方法,并了解 data loader 或手动 resolver 如何获取关联的 resources。

由索引模型根据 Issue 内容生成。

评估

技术栈
go, graphql, mongodb
领域
backend, databases
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。