mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 01:47:45 +03:00 
			
		
		
		
	Improved examples. Fixed #45
This commit is contained in:
		
							parent
							
								
									1ce85806fb
								
							
						
					
					
						commit
						b564e144df
					
				
							
								
								
									
										31
									
								
								examples/complex_example.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								examples/complex_example.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,31 @@
 | 
			
		|||
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=graphene.Argument(GeoInput))
 | 
			
		||||
 | 
			
		||||
    def resolve_address(self, args, 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
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
'''
 | 
			
		||||
 | 
			
		||||
result = schema.execute(query)
 | 
			
		||||
print(result.data['address']['latlng'])
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +21,7 @@ query = '''
 | 
			
		|||
        id
 | 
			
		||||
        name
 | 
			
		||||
      }
 | 
			
		||||
}
 | 
			
		||||
    }
 | 
			
		||||
'''
 | 
			
		||||
result = schema.execute(query)
 | 
			
		||||
print(result.data['patron'])
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user