The graphql schema generated by Generic subclasses is incorrect.
Consider this code.
class MyGeneric(Generic[T]):
...
@strawberry.type
class Child(MyGeneric[int]):
attr: int
@strawberry.type
class Parent:
child: Child
children: list[Child]
maybe_child: Child | None
annotated_child: Annotated[Child, 1]
@strawberry.type
class Query:
parent = strawberry.field(resolver=get_parent)
The generated schema is
type Parent {
annotatedChild: Child!
child: IntChild!
children: [Child!]!
maybeChild: Child
}
That is a problem, because I write the same object everywhere in my python code, but my graphql schema doesn't use the same name. It duplicates my types for no good reason. It makes the frontend code harder to write as the classes change depending on if they are contained/annotated.
Note that Child
itself will be a Child
(and not an IntChild
) when used as the root object.
I think the behaviour should be to have Child
everywhere. In a more generic way:
class GenericChild(MyGeneric[T]):
...
class Child(MyGeneric[int]):
...
class Parent:
generic_child : GenericChild[MyGeneric[int]]
concrete_child: Child
should give:
type Parent {
genericChild: IntGenericChild # This is a true generic which needs to be given details
concreteChild: Child # This is not a generic anymore and doesn't need details
}
What do you say?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too