Open blueyed opened 1 year ago
hey @blueyed ,
Hrm, I wonder if the issue has to do with the fact that the base type is not a dataclass. Maybe defining it as:
@dataclasses.dataclass
class UrnFieldMixin:
urn: str = django_field()
But not really sure...
Yeah, that fixes it. Thanks!
Might be worth adding to the documentation? (where?) Could it also be detected and handled with a clearer error message then?
Yeah, that fixes it. Thanks!
Might be worth adding to the documentation? (where?) Could it also be detected and handled with a clearer error message then?
Yeah, for sure! I think this actually applies to any dataclass implementation where you are trying to do introspection in it. It is probably because it uses dataclasses.fields
to extract the fields, so if an annotation was defined in a class that is not a dataclass it won't be retrieved by it.
Maybe what might be confusing is that someone might not know that @strawberry.type
is basically the same as @dataclasses.dataclass
with some extra functionalities (it calls dataclasses.dataclass
behind the scenes), so any rules applied to dataclasses also applies to strawberry types.
Unfortunately it also causes only
to not be applied/considered.
Do you think this could that be done/handled? It's likely because it is not on the concrete class itself, but via the mixin.
My idea with the mixin was to define a common field only once, but can do it explicitly then - without the mixin class.
@blueyed mixins work, but issue is that the mixin should also be a dataclass/strawberry type, otherwise their annotations won't be considered as fields.
Given:
I get:
When not using a mixin, or when not using strawberry-django-plus it works.
I am happy to debug this further, but would appreciate some pointer(s).