Open Mapiarz opened 1 year ago
Hi @Mapiarz ,
The issue here is that you are using auto
inside a dataclass. It would also have the same issue when using @strawberry.type
When using auto
, you want to do that inside a @strawberry_django.type
class, just like I mentioned in this comment
@bellini666 Hey! Fair point about the dataclass. Nonetheless:
strawberry_django.type
has to be related to a specific django model. What if I want to reuse the base strawberry_django.type
for multiple types associated with different django models? (this is not shown in my initial example above but that's my real world use case). Can I associate a strawberry_django.type
with an abstract base django model? strawberry_django.type
I still get the same issue. Could it have something to do with inheritance? In my example, SomeModel
get's the name
field from a base abstract model.It works with dataclass for the filter
Hrm, wondering if it has anything to do with the fact that inputs are handled differently.
Maybe there's something we can do to improve that for types as well?
A strawberry_django.type has to be related to a specific django model. What if I want to reuse the base strawberry_django.type for multiple types associated with different django models? (this is not shown in my initial example above but that's my real world use case). Can I associate a strawberry_django.type with an abstract base django model?
There are some possibilities here:
1) When using a dataclass or a strawberry.type
, you can use the type annotation directly instead of auto
. The main issue here is using auto
in a non strawberry_django.type
class.
2) I have some cases like this. Like, I have a base model or a mixin which I use on other models, and I want to reuse a type for that base model/mixin as well. What I usually do is to create an @strawberry_django.interface(BaseModelOrMixin)
and inherit my types from it. Not only this solves the auto issue, but also expose some useful interfaces in the schema.
obs. I still think that we can find a way to solve this issue. Maybe not for @dataclasses.dataclass
, but at least for @strawberry.type
. But in the meantime you can use one of those 2 workarounds
Even if I try to use strawberry_django.type I still get the same issue. Could it have something to do with inheritance? In my example, SomeModel get's the name field from a base abstract model.
Can you give me an example of this?
Describe the Bug
Consider code below
The filter will work just fine but the order will crash the schema converter. If I remove
OrderBase
and inline the name annotation inOrder
then everything works as inteded.Stacktrace:
System Information
Upvote & Fund