Skip to content

Commit 4677677

Browse files
committed
Merge pull request #39 from amitsaha/field_example
Example of querying a Python object
2 parents 6c7cb40 + f3f210b commit 4677677

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/field_example.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import graphene
2+
3+
4+
class Patron(graphene.ObjectType):
5+
id = graphene.ID()
6+
name = graphene.String()
7+
age = graphene.ID()
8+
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(result.data['patron'])

0 commit comments

Comments
 (0)