mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 09:57:41 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			44 lines
		
	
	
		
			903 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			903 B
		
	
	
	
		
			Python
		
	
	
	
	
	
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):
 | 
						|
    address = graphene.Field(Address, geo=GeoInput())
 | 
						|
 | 
						|
    def resolve_address(self, args, context, info):
 | 
						|
        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
 | 
						|
      }
 | 
						|
    }
 | 
						|
'''
 | 
						|
 | 
						|
 | 
						|
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'])
 |