Example of using a Python class as a field

This commit is contained in:
Amit Saha 2015-11-20 11:12:46 +11:00
parent b1d79c4f07
commit 25c59833cc

30
examples/field_example.py Normal file
View File

@ -0,0 +1,30 @@
import graphene
class Person(graphene.Interface):
name = graphene.String()
age = graphene.ID()
class Patron(Person):
id = graphene.ID()
class Query(graphene.ObjectType):
patron = graphene.Field(Patron)
def resolve_patron(self, args, info):
return Patron(id=1, name='Demo')
schema = graphene.Schema(query=Query)
query = '''
query something{
patron {
id
name
}
}
'''
result = schema.execute(query)
# Print the result
print result.data['patron']