strawberry-django-plus
strawberry-django-plus copied to clipboard
Have a relay.connection field on a django.type?
I think this should be allowed? We had a similar schema with graphene:
@gql.django.type(SkillModule)
class SkillModuleType(gql.relay.Node):
id: gql.relay.GlobalID
order: int
name: str
description: str
@gql.relay.connection
def active_skill_list(self: SkillModule) -> List["SkillType"]:
return self.skill_set.filter(is_active=True)
@gql.relay.connection
def published_skill_list(self: SkillModule) -> List["SkillType"]:
return self.skill_set.filter(is_published=True, is_active=True)
File "/code/.../types.py", line 48, in <module>
class SkillModuleType(gql.relay.Node):
File "/usr/local/lib/python3.9/site-packages/strawberry_django_plus/type.py", line 396, in wrapper
return _process_type(
File "/usr/local/lib/python3.9/site-packages/strawberry_django_plus/type.py", line 281, in _process_type
fields = list(_get_fields(django_type).values())
File "/usr/local/lib/python3.9/site-packages/strawberry_django_plus/type.py", line 233, in _get_fields
fields[name] = _from_django_type(django_type, name)
File "/usr/local/lib/python3.9/site-packages/strawberry_django_plus/type.py", line 173, in _from_django_type
elif field.django_name or field.is_auto:
AttributeError: 'ConnectionField' object has no attribute 'django_name'
Yes, nested connections should be supported.
For curiosity, does changing gql.relay.connection
to gql.django.connection
fixes your issue? If not, I'll take a look in what might be happening there
Yes, that fixes the issue. I didn't know gql.django.connection
was a thing. I think the thing to do here is just update the readme letting people know they need to use gql.django.connection
on @gql.django.type
not gql.relay.connection
. Maybe in the relay section and the django section.