From 9cf4da5fcb821019ec871755927fa92cd56f12bf Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sat, 4 Jun 2016 14:14:56 -0700 Subject: [PATCH] Improved simple example --- examples/simple_example.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/examples/simple_example.py b/examples/simple_example.py index bc4b9d34..2bc9b44f 100644 --- a/examples/simple_example.py +++ b/examples/simple_example.py @@ -4,15 +4,15 @@ import graphene class Patron(graphene.ObjectType): id = graphene.ID() name = graphene.String() - age = graphene.ID() + age = graphene.Int() class Query(graphene.ObjectType): patron = graphene.Field(Patron) - def resolve_patron(self, args, info): - return Patron(id=1, name='Demo') + def resolve_patron(self, args, context, info): + return Patron(id=1, name='Syrus', age=27) schema = graphene.Schema(query=Query) query = ''' @@ -20,8 +20,24 @@ query = ''' patron { id name + age } } ''' -result = schema.execute(query) -print(result.data['patron']) + + +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'])