Changed to strawberry #181

This commit is contained in:
2025-09-27 18:25:50 +02:00
parent a35b44b3b5
commit ada50c693e
19 changed files with 317 additions and 230 deletions

View File

@@ -1,5 +1,5 @@
from cpl.graphql.schema.filter.filter import Filter
from cpl.graphql.schema.object_graph_type import ObjectGraphType
from cpl.graphql.schema.graph_type import GraphType
from cpl.graphql.schema.sort.sort import Sort
from cpl.graphql.schema.sort.sort_order import SortOrder
@@ -25,15 +25,15 @@ class CitySort(Sort[City]):
self.field("name", SortOrder)
class CityGraphType(ObjectGraphType):
class CityGraphType(GraphType[City]):
def __init__(self):
ObjectGraphType.__init__(self)
GraphType.__init__(self)
self.string_field(
self.int_field(
"id",
resolver=lambda user, *_: user.id,
resolver=lambda root: root.id,
)
self.string_field(
"name",
resolver=lambda user, *_: user.name,
resolver=lambda root: root.name,
)

View File

@@ -11,7 +11,7 @@ class HelloQuery(Query):
Query.__init__(self)
self.string_field(
"message",
resolver=lambda *_, name: f"Hello {name} {get_request().state.request_id}",
resolver=lambda name: f"Hello {name} {get_request().state.request_id}",
).with_argument(str, "name", "Name to greet", "world")
self.collection_field(
@@ -19,12 +19,12 @@ class HelloQuery(Query):
"users",
UserFilter,
UserSort,
resolver=lambda *_: users,
resolver=lambda: users,
)
self.collection_field(
CityGraphType,
"cities",
CityFilter,
CitySort,
resolver=lambda *_: cities,
resolver=lambda: cities,
)

View File

@@ -1,6 +1,5 @@
from cpl.graphql.schema.filter.filter import Filter
from cpl.graphql.schema.object_graph_type import ObjectGraphType
from cpl.graphql.schema.graph_type import GraphType
from cpl.graphql.schema.sort.sort import Sort
from cpl.graphql.schema.sort.sort_order import SortOrder
@@ -25,15 +24,16 @@ class UserSort(Sort[User]):
self.field("name", SortOrder)
class UserGraphType(ObjectGraphType):
def __init__(self):
ObjectGraphType.__init__(self)
class UserGraphType(GraphType[User]):
self.string_field(
def __init__(self):
GraphType.__init__(self)
self.int_field(
"id",
resolver=lambda user, *_: user.id,
resolver=lambda root: root.id,
)
self.string_field(
"name",
resolver=lambda user, *_: user.name,
resolver=lambda root: root.name,
)