Queries
Queries can be written using strawberry_django.field()
to load the fields defined in the types.py
file.
import strawberryimport strawberry_django
from .types import Fruit
@strawberry.typeclass Query:
fruit: Fruit = strawberry_django.field() fruits: list[Fruit] = strawberry_django.field()
schema = strawberry.Schema(query=Query)
Tip
You must name your query class βQueryβ or decorate it with @strawberry.type(name="Query")
for the single query default primary filter to work
For the single queries (like Fruit
above), Strawberry comes with a default primary key search filter in the GraphiQL interface. The query Fruits
gets all the objects in the Fruits by default. To query specific sets of objects a filter need to be added in the types.py
file.