2015-11-23 04:29:30 +03:00
|
|
|
import graphene
|
|
|
|
|
|
|
|
|
|
|
|
class GeoInput(graphene.InputObjectType):
|
|
|
|
lat = graphene.Float(required=True)
|
|
|
|
lng = graphene.Float(required=True)
|
|
|
|
|
|
|
|
|
|
|
|
class Address(graphene.ObjectType):
|
|
|
|
latlng = graphene.String()
|
|
|
|
|
|
|
|
|
|
|
|
class Query(graphene.ObjectType):
|
2016-06-05 02:04:21 +03:00
|
|
|
address = graphene.Field(Address, geo=GeoInput())
|
2015-11-23 04:29:30 +03:00
|
|
|
|
2016-06-05 01:22:10 +03:00
|
|
|
def resolve_address(self, args, context, info):
|
2015-11-23 04:29:30 +03:00
|
|
|
geo = args.get('geo')
|
|
|
|
return Address(latlng="({},{})".format(geo.get('lat'), geo.get('lng')))
|
|
|
|
|
|
|
|
|
|
|
|
schema = graphene.Schema(query=Query)
|
|
|
|
query = '''
|
|
|
|
query something{
|
|
|
|
address(geo: {lat:32.2, lng:12}) {
|
|
|
|
latlng
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
|
2016-06-05 01:22:10 +03:00
|
|
|
|
|
|
|
def test_query():
|
|
|
|
result = schema.execute(query)
|
|
|
|
assert not result.errors
|
|
|
|
assert result.data == {
|
|
|
|
'address': {
|
|
|
|
'latlng': "(32.2,12.0)",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
result = schema.execute(query)
|
|
|
|
print(result.data['address']['latlng'])
|