Uh oh!
There was an error while loading. Please reload this page.
forked from graphql-python/graphene
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_example.py
More file actions
Latest commit
69 lines (47 loc) · 1.43 KB
/
Copy pathcomplex_example.py
File metadata and controls
69 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
importgraphene
classGeoInput(graphene.InputObjectType):
lat=graphene.Float(required=True)
lng=graphene.Float(required=True)
@property
deflatlng(self):
returnf"({self.lat},{self.lng})"
classAddress(graphene.ObjectType):
latlng=graphene.String()
classQuery(graphene.ObjectType):
address=graphene.Field(Address, geo=GeoInput(required=True))
defresolve_address(root, info, geo):
returnAddress(latlng=geo.latlng)
classCreateAddress(graphene.Mutation):
classArguments:
geo=GeoInput(required=True)
Output=Address
defmutate(root, info, geo):
returnAddress(latlng=geo.latlng)
classMutation(graphene.ObjectType):
create_address=CreateAddress.Field()
schema=graphene.Schema(query=Query, mutation=Mutation)
query="""
query something{
address(geo: {lat:32.2, lng:12}) {
latlng
}
}
"""
mutation="""
mutation addAddress{
createAddress(geo: {lat:32.2, lng:12}) {
latlng
}
}
"""
deftest_query():
result=schema.execute(query)
assertnotresult.errors
assertresult.data== {"address": {"latlng": "(32.2,12.0)"}}
deftest_mutation():
result=schema.execute(mutation)
assertnotresult.errors
assertresult.data== {"createAddress": {"latlng": "(32.2,12.0)"}}
if__name__=="__main__":
result=schema.execute(query)
print(result.data["address"]["latlng"])