[WIP] collection #181
This commit is contained in:
39
example/api/src/queries/user.py
Normal file
39
example/api/src/queries/user.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from cpl.graphql.schema.filter.filter import Filter
|
||||
from cpl.graphql.schema.object_graph_type import ObjectGraphType
|
||||
|
||||
from cpl.graphql.schema.sort.sort import Sort
|
||||
from cpl.graphql.schema.sort.sort_order import SortOrder
|
||||
|
||||
|
||||
class User:
|
||||
def __init__(self, id: int, name: str):
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
|
||||
class UserFilter(Filter[User]):
|
||||
def __init__(self):
|
||||
Filter.__init__(self)
|
||||
self.field("id", int)
|
||||
self.field("name", str)
|
||||
|
||||
|
||||
class UserSort(Sort[User]):
|
||||
def __init__(self):
|
||||
Sort.__init__(self)
|
||||
self.field("id", SortOrder)
|
||||
self.field("name", SortOrder)
|
||||
|
||||
|
||||
class UserGraphType(ObjectGraphType):
|
||||
def __init__(self):
|
||||
ObjectGraphType.__init__(self)
|
||||
|
||||
self.string_field(
|
||||
"id",
|
||||
resolver=lambda user, *_: user.id,
|
||||
)
|
||||
self.string_field(
|
||||
"name",
|
||||
resolver=lambda user, *_: user.name,
|
||||
)
|
||||
Reference in New Issue
Block a user