Skip to content

Commit be51468

Browse files
committed
add explicit queries
1 parent 660bd18 commit be51468

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

api/schema/geography_schema.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Schema definitions for geographies."""
22

3+
from typing import List
4+
35
import strawberry
46
import strawberry_django
7+
from strawberry.types import Info
58

69
from api.models import Geography
710
from api.types.type_geo import TypeGeo
@@ -11,5 +14,14 @@
1114
class Query:
1215
"""Queries for geographies."""
1316

14-
geographies: list[TypeGeo] = strawberry_django.field()
15-
geography: TypeGeo = strawberry_django.field()
17+
@strawberry_django.field
18+
def geographies(self, info: Info) -> List[TypeGeo]:
19+
"""Get all geographies."""
20+
geographies = Geography.objects.all()
21+
return TypeGeo.from_django_list(geographies)
22+
23+
@strawberry_django.field
24+
def geography(self, info: Info, id: int) -> TypeGeo:
25+
"""Get a single geography by ID."""
26+
geography = Geography.objects.get(id=id)
27+
return TypeGeo.from_django(geography)

0 commit comments

Comments
 (0)