mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Exclude flake8 syntax in docs. Added tea_store example
This commit is contained in:
parent
18b66bd8a2
commit
a556ab89f4
8
docs/playground/examples/tea_store.graphql
Normal file
8
docs/playground/examples/tea_store.graphql
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
query {
|
||||||
|
store {
|
||||||
|
teas(orderBy:"name") {
|
||||||
|
name
|
||||||
|
steepingTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
docs/playground/examples/tea_store.schema.py
Normal file
38
docs/playground/examples/tea_store.schema.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import graphene
|
||||||
|
|
||||||
|
class Tea(graphene.ObjectType):
|
||||||
|
name = graphene.String()
|
||||||
|
steeping_time = graphene.Int()
|
||||||
|
|
||||||
|
TEAS = [
|
||||||
|
Tea(name='Earl Grey Blue Star', steeping_time=5),
|
||||||
|
Tea(name='Milk Oolong', steeping_time=3),
|
||||||
|
Tea(name='Gunpowder Golden Temple', steeping_time=3),
|
||||||
|
Tea(name='Assam Hatimara', steeping_time=5),
|
||||||
|
Tea(name='Bancha', steeping_time=2),
|
||||||
|
Tea(name='Ceylon New Vithanakande', steeping_time=5),
|
||||||
|
Tea(name='Golden Tip Yunnan', steeping_time=5),
|
||||||
|
Tea(name='Jasmine Phoenix Pearls', steeping_time=3),
|
||||||
|
Tea(name='Kenya Milima', steeping_time=5),
|
||||||
|
Tea(name='Pu Erh First Grade', steeping_time=4),
|
||||||
|
Tea(name='Sencha Makoto', steeping_time=3),
|
||||||
|
]
|
||||||
|
|
||||||
|
class Store(graphene.ObjectType):
|
||||||
|
teas = graphene.List(Tea, order_by=graphene.String())
|
||||||
|
|
||||||
|
def resolve_teas(self, args, info):
|
||||||
|
order_by = args.get("order_by")
|
||||||
|
if order_by == "steepingTime":
|
||||||
|
return sorted(self.teas, key=lambda tea: tea.steeping_time)
|
||||||
|
elif order_by == "name":
|
||||||
|
return sorted(self.teas, key=lambda tea: tea.name)
|
||||||
|
return self.teas
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
store = graphene.Field(Store)
|
||||||
|
|
||||||
|
def resolve_store(self, args, info):
|
||||||
|
return Store(teas=TEAS)
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
Loading…
Reference in New Issue
Block a user