documentation, cleanup

This commit is contained in:
Anatol Ulrich
2023-10-04 22:25:21 +02:00
parent fa52233404
commit d33b57cff8
7 changed files with 171 additions and 61 deletions

View File

@ -44,16 +44,13 @@ class Mutation:
"""
Operation to order a pizza
"""
@strawberry.mutation
def order_pizza(self, name: str, toppings: typing.List[str], info: auth.Info) -> OrderInfo:
@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)
token = info.context.token
has_permission = auth.validate_permissions(token, "orderPizza")
if not has_permission:
raise auth.SecurityException("Permission denied")
return OrderInfo(
id=str(randint(1, 100000)),
deliveryTime=str(datetime.now()),
@ -62,20 +59,13 @@ class Mutation:
)
def empty():
"""
empty resolver for stub query (see below)
"""
@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=empty)
stub: str = strawberry.field(resolver=lambda: ...)
# query= is required: https://strawberry.rocks/docs/general/mutations
schema = strawberry.Schema(query=Query, mutation=Mutation)