The following code:
import strawberry
from typing import Generic, TypeVar
T = TypeVar("T")
@strawberry.type
class User(Generic[T]):
name: str
age: int
def something(self) -> T:
return 1
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User[int]:
return User(name="Patrick", age=100)
schema = strawberry.Schema(query=Query)
generates the following schema:
type IntUser {
name: String!
age: Int!
}
type Query {
user: IntUser!
}
I think we could add some more logic to when checking if a type is generic to prevent having generic types when the type vars are not used for field types or for argument types :)
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