Open edouardruiz opened 3 years ago
We haven't looked at GenericRelation
which means that it is not supported yet. Would you like to contribute? :)
To add to this, GenericRelation
should be supported, even by the optimizer. A way to make it work is to define a common "interface" between those types and type the return value with that interface. That is needed because GraphQL
enforces typing very strictly and it can't be told to "return anything"
An example would be:
@strawberry_django.interface(CommonAbstractModelBetweenModels)
class SomeInterface:
...
@strawberry_djang.type(Foo)
class FooType(SomeInterface):
...
@strawberry_django.type(Bar)
class BarType(SomeInterface):
...
@strawberry_django.type(Parent)
class ParentType:
generic_relation: list[SomeInterface]
Will keep this open and mark it as documentation to add an example at the docs
Hi,
It seems that Django GenericRelation isn't handled correctly. Using
@straberry_django.type
decorator with one of my models results in aKeyError: <class 'django.contrib.contenttypes.fields.GenericRelation'>
and it's missing in thefield_type_map
instrawberry_django.fields.types
.My current workaround is to define a field with a custom resolver.
Am I missing something and if not is there any plan to support this type of field?
Upvote & Fund