Skip to content

Commit b564e14

Browse files
committed
Improved examples. Fixed #45
1 parent 1ce8580 commit b564e14

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

examples/complex_example.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import graphene
2+
3+
4+
class GeoInput(graphene.InputObjectType):
5+
lat = graphene.Float(required=True)
6+
lng = graphene.Float(required=True)
7+
8+
9+
class Address(graphene.ObjectType):
10+
latlng = graphene.String()
11+
12+
13+
class Query(graphene.ObjectType):
14+
address = graphene.Field(Address, geo=graphene.Argument(GeoInput))
15+
16+
def resolve_address(self, args, info):
17+
geo = args.get('geo')
18+
return Address(latlng="({},{})".format(geo.get('lat'), geo.get('lng')))
19+
20+
21+
schema = graphene.Schema(query=Query)
22+
query = '''
23+
query something{
24+
address(geo: {lat:32.2, lng:12}) {
25+
latlng
26+
}
27+
}
28+
'''
29+
30+
result = schema.execute(query)
31+
print(result.data['address']['latlng'])

examples/field_example.py renamed to examples/simple_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def resolve_patron(self, args, info):
2121
id
2222
name
2323
}
24-
}
24+
}
2525
'''
2626
result = schema.execute(query)
2727
print(result.data['patron'])

0 commit comments

Comments
 (0)