graphql-python / graphql-python/graphene-sqlalchemy

Union types in connections: 'UnionOptions' object has no attribute 'model'

未关闭
#415 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
985
派生
223
PR 合并指标
30 天内没有已合并 PR

描述

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,
)
```

```@property
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?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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