Skip to content

Commit 7af4137

Browse files
committed
Example of querying a Python object
1 parent 3712542 commit 7af4137

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/field_example.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import graphene
2+
3+
class Person(graphene.Interface):
4+
name = graphene.String()
5+
age = graphene.ID()
6+
7+
class Patron(Person):
8+
id = graphene.ID()
9+
10+
class Query(graphene.ObjectType):
11+
12+
patron = graphene.Field(Patron)
13+
14+
def resolve_patron(self, args, info):
15+
return Patron(id=1, name='Demo')
16+
17+
schema = graphene.Schema(query=Query)
18+
query = '''
19+
query something{
20+
patron {
21+
id
22+
name
23+
}
24+
}
25+
'''
26+
result = schema.execute(query)
27+
# Print the result
28+
print result.data['patron']
29+
30+

0 commit comments

Comments
 (0)