All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 6s
71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
from queries.cities import CityFilter, CitySort, CityGraphType, City
|
|
from queries.user import User, UserFilter, UserSort, UserGraphType
|
|
from cpl.api.middleware.request import get_request
|
|
from cpl.auth.schema import UserDao, User
|
|
from cpl.graphql.schema.filter.filter import Filter
|
|
from cpl.graphql.schema.graph_type import GraphType
|
|
from cpl.graphql.schema.query import Query
|
|
from cpl.graphql.schema.sort.sort import Sort
|
|
from cpl.graphql.schema.sort.sort_order import SortOrder
|
|
|
|
users = [User(i, f"User {i}") for i in range(1, 101)]
|
|
cities = [City(i, f"City {i}") for i in range(1, 101)]
|
|
|
|
# class UserFilter(Filter[User]):
|
|
# def __init__(self):
|
|
# Filter.__init__(self)
|
|
# self.field("id", int)
|
|
# self.field("username", str)
|
|
#
|
|
#
|
|
# class UserSort(Sort[User]):
|
|
# def __init__(self):
|
|
# Sort.__init__(self)
|
|
# self.field("id", SortOrder)
|
|
# self.field("username", SortOrder)
|
|
#
|
|
# class UserGraphType(GraphType[User]):
|
|
#
|
|
# def __init__(self):
|
|
# GraphType.__init__(self)
|
|
#
|
|
# self.int_field(
|
|
# "id",
|
|
# resolver=lambda root: root.id,
|
|
# )
|
|
# self.string_field(
|
|
# "username",
|
|
# resolver=lambda root: root.username,
|
|
# )
|
|
|
|
|
|
class HelloQuery(Query):
|
|
def __init__(self):
|
|
Query.__init__(self)
|
|
self.string_field(
|
|
"message",
|
|
resolver=lambda name: f"Hello {name} {get_request().state.request_id}",
|
|
).with_argument("name", str, "Name to greet", "world")
|
|
|
|
self.collection_field(
|
|
UserGraphType,
|
|
"users",
|
|
UserFilter,
|
|
UserSort,
|
|
resolver=lambda: users,
|
|
)
|
|
self.collection_field(
|
|
CityGraphType,
|
|
"cities",
|
|
CityFilter,
|
|
CitySort,
|
|
resolver=lambda: cities,
|
|
)
|
|
# self.dao_collection_field(
|
|
# UserGraphType,
|
|
# UserDao,
|
|
# "Users",
|
|
# UserFilter,
|
|
# UserSort,
|
|
# )
|