mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Merge pull request #39 from amitsaha/field_example
Example of querying a Python object
This commit is contained in:
		
						commit
						4677677ee9
					
				
							
								
								
									
										27
									
								
								examples/field_example.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								examples/field_example.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | ||||||
|  | import graphene | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Patron(graphene.ObjectType): | ||||||
|  |     id = graphene.ID() | ||||||
|  |     name = graphene.String() | ||||||
|  |     age = graphene.ID() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Query(graphene.ObjectType): | ||||||
|  | 
 | ||||||
|  |     patron = graphene.Field(Patron) | ||||||
|  | 
 | ||||||
|  |     def resolve_patron(self, args, info): | ||||||
|  |         return Patron(id=1, name='Demo') | ||||||
|  | 
 | ||||||
|  | schema = graphene.Schema(query=Query) | ||||||
|  | query = ''' | ||||||
|  |     query something{ | ||||||
|  |       patron { | ||||||
|  |         id | ||||||
|  |         name | ||||||
|  |       } | ||||||
|  | } | ||||||
|  | ''' | ||||||
|  | result = schema.execute(query) | ||||||
|  | print(result.data['patron']) | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user