When I was working with the documentation improvements the other week, one area where I realised I was struggling was the difference between @strawberry.type
and @strawberry_django.type
.
See my comments in the code below (extracted from that featured in the docs):
import strawberry
import strawberry_django
from strawberry import auto
from .. import model
# It makes sense that a Type is wrapped as a type
@strawberry_django.type(models.Fruit)
class FruitType:
id: auto
name: auto
category: auto
color: "ColorType"
# It makes sense that a Type is wrapped as a type
@strawberry_django.type(models.Color)
class ColorType:
id: auto
name: auto
fruits: list[
FruitType
]
# It doesn't make sense that a Query is wrapped as a type
@strawberry.type
class FruitQueries:
fruits: list[FruitType] = strawberry_django.field()
# (it's also not quite obvious how strawberry_django.field() works here but that's for another issue I guess)
What about, within strawberry-django
, we do:
from strawberry import type as query
# Or possibly something similar but with different docstring explaining what this is for
Then the last section of the code above looks like:
# It makes sense that a Query is wrapped as a query
@strawberry_django.query
class FruitQueries:
fruits: list[FruitType] = strawberry_django.field()
I think this solution has the following benefits:
strawberry_django
to avoid digging immediately into the much bigger and more complex strawberry docsLess than an hour. I'm happy to make this PR myself and update documentation to match if my suggestion has the blessing of the maintainers, no breaking changes required.
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