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)
|
|
|
|
|
2016-06-05 00:14:56 +03:00
|
|
|
def resolve_patron(self, args, context, 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 = '''
|
|
|
|
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
|
|
|
}
|
2015-11-20 03:19:22 +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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
result = schema.execute(query)
|
|
|
|
print(result.data['patron'])
|