mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Improved simple example
This commit is contained in:
parent
89790e7508
commit
9cf4da5fcb
|
@ -4,15 +4,15 @@ import graphene
|
||||||
class Patron(graphene.ObjectType):
|
class Patron(graphene.ObjectType):
|
||||||
id = graphene.ID()
|
id = graphene.ID()
|
||||||
name = graphene.String()
|
name = graphene.String()
|
||||||
age = graphene.ID()
|
age = graphene.Int()
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
|
|
||||||
patron = graphene.Field(Patron)
|
patron = graphene.Field(Patron)
|
||||||
|
|
||||||
def resolve_patron(self, args, info):
|
def resolve_patron(self, args, context, info):
|
||||||
return Patron(id=1, name='Demo')
|
return Patron(id=1, name='Syrus', age=27)
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
||||||
query = '''
|
query = '''
|
||||||
|
@ -20,8 +20,24 @@ query = '''
|
||||||
patron {
|
patron {
|
||||||
id
|
id
|
||||||
name
|
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'])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user