graphene/examples/simple_example.py

39 lines
691 B
Python
Raw Permalink Normal View History

2015-11-20 03:19:22 +03:00
import graphene
2015-11-20 03:47:10 +03:00
class Patron(graphene.ObjectType):
id = graphene.ID()
2015-11-20 03:19:22 +03:00
name = graphene.String()
2016-06-05 00:14:56 +03:00
age = graphene.Int()
2015-11-20 03:19:22 +03:00
2015-11-20 03:47:10 +03:00
2015-11-20 03:19:22 +03:00
class Query(graphene.ObjectType):
patron = graphene.Field(Patron)
def resolve_patron(root, info):
return Patron(id=1, name="Syrus", age=27)
2015-11-20 03:19:22 +03:00
2017-07-13 07:45:06 +03:00
2015-11-20 03:19:22 +03:00
schema = graphene.Schema(query=Query)
query = """
2015-11-20 03:19:22 +03:00
query something{
patron {
id
name
2016-06-05 00:14:56 +03:00
age
2015-11-20 03:19:22 +03:00
}
2015-11-23 04:29:30 +03:00
}
"""
2016-06-05 00:14:56 +03:00
def test_query():
result = schema.execute(query)
assert not result.errors
assert result.data == {"patron": {"id": "1", "name": "Syrus", "age": 27}}
2016-06-05 00:14:56 +03:00
if __name__ == "__main__":
2016-06-05 00:14:56 +03:00
result = schema.execute(query)
print(result.data["patron"])