40 lines
913 B
Python
40 lines
913 B
Python
from cpl.graphql.schema.filter.filter import Filter
|
|
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
|
|
|
|
|
|
class City:
|
|
def __init__(self, id: int, name: str):
|
|
self.id = id
|
|
self.name = name
|
|
|
|
|
|
class CityFilter(Filter[City]):
|
|
def __init__(self):
|
|
Filter.__init__(self)
|
|
self.field("id", int)
|
|
self.field("name", str)
|
|
|
|
|
|
class CitySort(Sort[City]):
|
|
def __init__(self):
|
|
Sort.__init__(self)
|
|
self.field("id", SortOrder)
|
|
self.field("name", SortOrder)
|
|
|
|
|
|
class CityGraphType(GraphType[City]):
|
|
def __init__(self):
|
|
GraphType.__init__(self)
|
|
|
|
self.int_field(
|
|
"id",
|
|
resolver=lambda root: root.id,
|
|
)
|
|
self.string_field(
|
|
"name",
|
|
resolver=lambda root: root.name,
|
|
)
|