python - 在 graphql 查询中包含参考字段
问题描述
我最近使用 graphen-mongo 开始使用 graphql,我很难弄清楚以下用例是否可以按照我现在的方式进行。
我有一个看起来像这样的模型
class ParentModel(Document):
meta = {'collection': 'parent'}
title = StringField()
name = StringField()
class ChildModel(Document):
meta = {'collection': 'child'}
parent = ReferenceField(ParentModel)
child_name = StringField()
child_age = IntField()
child_gender = EnumField(GenderEnum)
和类型定义为
class ParentType(MongoengineObjectType):
class Meta:
model = ParentModel
interfaces = (Node,)
class ChildType(MongoengineObjectType):
class Meta:
model = ChildModel
interfaces = (Node,)
最后,下面的查询返回parent
来自 mongo 的所有 's。
class ParentQuery(ObjectType):
parent_query = MongoengineConnectionField(ParentType)
到目前为止,一切都很好。
我现在想弄清楚的是,child
在parent
查询parent
. 有人可以请教。
注意:远离嵌入式文档
解决方案
推荐阅读
- sql - SQL/Doctrine - 使用 AND 过滤结果(多对多)
- angular - ng2-search-filter 在离子 4 中给出错误
- datetime - 类 ClockTriggerBuilder:特定日期和时间(仅一次)Google Sheet 脚本中的触发器每分钟不断重复执行
- react-hooks - 设置状态完成后如何调用函数(React Hooks)
- c# - 如何在另一个数据库中创建模式
- python - OSError:118 与 esp32
- git - Visual Studio 2019“推送到远程存储库时遇到错误:无法推送到远程存储库...”
- .net - 无法为 '.NETCoreApp,Version=v3.1 解析'Microsoft.EntityFrameworkCore (>= 3.1.7)'
- python - 在 Pandas 中创建每周个人资料
- html - 尽管将位置更改为静态,但 CSS 导航栏仍固定在顶部