2015-11-20 03:19:22 +03:00
|
|
|
import graphene
|
|
|
|
|
2015-11-20 03:47:10 +03:00
|
|
|
|
2015-11-20 08:25:18 +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)
|
|
|
|
|
2020-03-15 21:52:56 +03:00
|
|
|
def resolve_patron(root, info):
|
2018-07-06 22:09:23 +03:00
|
|
|
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)
|
2018-07-06 22:09:23 +03:00
|
|
|
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
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2016-06-05 00:14:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_query():
|
|
|
|
result = schema.execute(query)
|
|
|
|
assert not result.errors
|
2018-07-06 22:09:23 +03:00
|
|
|
assert result.data == {"patron": {"id": "1", "name": "Syrus", "age": 27}}
|
2016-06-05 00:14:56 +03:00
|
|
|
|
|
|
|
|
2018-07-06 22:09:23 +03:00
|
|
|
if __name__ == "__main__":
|
2016-06-05 00:14:56 +03:00
|
|
|
result = schema.execute(query)
|
2018-07-06 22:09:23 +03:00
|
|
|
print(result.data["patron"])
|