From 25c59833ccc877c7f8258d0e8dcfabace11f19ce Mon Sep 17 00:00:00 2001 From: Amit Saha Date: Fri, 20 Nov 2015 11:12:46 +1100 Subject: [PATCH] Example of using a Python class as a field --- examples/field_example.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/field_example.py diff --git a/examples/field_example.py b/examples/field_example.py new file mode 100644 index 00000000..f9218d0e --- /dev/null +++ b/examples/field_example.py @@ -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'] + +