76 lines
1.5 KiB
Python
76 lines
1.5 KiB
Python
"""
|
|
GraphQL schema definitions
|
|
|
|
Author(s): anatol.ulrich@basebox.io
|
|
|
|
Copyright (c) 2023 basebox GmbH. All rights reserved.
|
|
"""
|
|
|
|
# stdlib imports
|
|
from random import randint
|
|
from datetime import datetime
|
|
import typing
|
|
import logging
|
|
|
|
# dependencies imports
|
|
import strawberry
|
|
|
|
# app imports
|
|
import consts
|
|
import auth
|
|
|
|
|
|
logger = logging.getLogger(consts.LOG_ROOT)
|
|
|
|
|
|
@strawberry.type
|
|
class Pizza:
|
|
"""
|
|
Pizza
|
|
"""
|
|
name: str
|
|
toppings: typing.List[str]
|
|
|
|
|
|
@strawberry.type
|
|
class OrderInfo:
|
|
"""
|
|
Information about a pizza order
|
|
"""
|
|
id: str
|
|
deliveryTime: str
|
|
bakerName: str
|
|
pizza: Pizza
|
|
|
|
|
|
@strawberry.type
|
|
class Mutation:
|
|
"""
|
|
Operation to order a pizza
|
|
"""
|
|
@strawberry.mutation(permission_classes=[auth.BBPermission])
|
|
def order_pizza(self, name: str, toppings: typing.List[str]) -> OrderInfo:
|
|
"""
|
|
Order a pizza with a name and list of toppings
|
|
"""
|
|
logger.debug("orderPizza name=%s toppings=%s", name, toppings)
|
|
|
|
return OrderInfo(
|
|
id=str(randint(1, 100000)),
|
|
deliveryTime=str(datetime.now()),
|
|
bakerName="Domino's",
|
|
pizza=Pizza(name=name, toppings=toppings)
|
|
)
|
|
|
|
|
|
@strawberry.type
|
|
class Query:
|
|
"""
|
|
`strawberry.Schema` requires at least one `Query`, so configure a stub
|
|
see https://strawberry.rocks/docs/general/mutations
|
|
"""
|
|
stub: str = strawberry.field(resolver=lambda: ...)
|
|
|
|
|
|
schema = strawberry.Schema(query=Query, mutation=Mutation)
|