File: queries.md

package info (click to toggle)
strawberry-graphql-django 0.62.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,968 kB
  • sloc: python: 27,530; sh: 17; makefile: 16
file content (29 lines) | stat: -rw-r--r-- 846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---
title: Queries
---

# Queries

Queries can be written using `strawberry_django.field()` to load the fields defined in the `types.py` file.

```python
#schema.py

import strawberry
import strawberry_django

from .types import Fruit

@strawberry.type
class 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.