Union types in connections: 'UnionOptions' object has no attribute 'model'
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with SQLAlchemyConnectionField.wrap_resolve() and its model property, then reproduce the reported query using a Graphene union of SQLAlchemyObjectType classes. Trace how the union's _meta data reaches the connection resolver; done requires defining how connections with multiple underlying models should be handled without the reported UnionOptions.model error.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- Python
- Stars
- 985
- Forks
- 224
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphene-sqlalchemy
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
graphql-python/graphene-sqlalchemy#422 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
graphql-python/graphene-sqlalchemy#419 · 3 comments ·
All issues in graphql-python/graphene-sqlalchemy
Similar issues
-
essnmx good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
[Feature] 奇物选择添加优先级 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Giskard-AI/giskard-oss#2840 · 1 comment ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Openarea: repo bug perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yeti-platform/yeti#1380 ·