Union types in connections: 'UnionOptions' object has no attribute 'model'
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
调研方向
从 SQLAlchemyConnectionField.wrap_resolve() 及其 model 属性入手,然后使用由 SQLAlchemyObjectType 类组成的 Graphene union 重现报告中的查询。跟踪 union 的 _meta 数据如何传递到 connection resolver;完成这项工作需要定义如何处理具有多个底层模型的 connection,同时避免报告中的 UnionOptions.model 错误。
由索引模型根据 Issue 内容生成。
描述
Are there plans to add support for union types in connections? I have a setup like the following:
class Cat(SQLAlchemyObjectType):
class Meta:
model = CatModel
interfaces = (relay.Node,)
class Dog(SQLAlchemyObjectType):
class Meta:
model = DogModel
interfaces = (relay.Node,)
class Animal(graphene.Union):
class Meta:
types = (Cat, Dog)
class Query(graphene.ObjectType):
animals = SQLAlchemyConnectionField(Animal)
and when I try to query for animals, I get the error: 'UnionOptions' object has no attribute 'model'.
I traced this back to the self.model call in wrap_resolve():
def wrap_resolve(self, parent_resolver):
return partial(
self.connection_resolver,
parent_resolver,
get_nullable_type(self.type),
self.model,
)
def model(self):
return get_nullable_type(self.type)._meta.node._meta.model
When the type is a union, get_nullable_type(self.type)._meta.node._meta returns the union class (in this case Animal). In order to get a model from that, we have to drill down into its types (e.g. get_nullable_type(self.type)._meta.node._meta.types[0]._meta.model) but because it's a union, it will contain multiple models.
Any ideas how to get around this?
- 主要语言
- Python
- 星标
- 985
- 派生
- 224
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql-python/graphene-sqlalchemy 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 25/100
graphql-python/graphene-sqlalchemy#422 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
graphql-python/graphene-sqlalchemy#419 · 3 条评论 ·
查看 graphql-python/graphene-sqlalchemy 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·