mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 09:57:41 +03:00 
			
		
		
		
	Merge pull request #412 from BossGrand/master
Added documentation on how to accept files in a mutation
This commit is contained in:
		
						commit
						eb1ded2a65
					
				| 
						 | 
					@ -27,3 +27,29 @@ subclass of ``relay.ClientIDMutation``.
 | 
				
			||||||
            ship = create_ship(ship_name, faction_id)
 | 
					            ship = create_ship(ship_name, faction_id)
 | 
				
			||||||
            faction = get_faction(faction_id)
 | 
					            faction = get_faction(faction_id)
 | 
				
			||||||
            return IntroduceShip(ship=ship, faction=faction)
 | 
					            return IntroduceShip(ship=ship, faction=faction)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Accepting Files
 | 
				
			||||||
 | 
					-------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Mutations can also accept files, they will be in the context variable.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.. code:: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class UploadFile(graphene.ClientIDMutation):
 | 
				
			||||||
 | 
					         class Input:
 | 
				
			||||||
 | 
					             pass
 | 
				
			||||||
 | 
					             # nothing needed for uploading file
 | 
				
			||||||
 | 
					     
 | 
				
			||||||
 | 
					         # your return fields
 | 
				
			||||||
 | 
					         success = graphene.String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @classmethod
 | 
				
			||||||
 | 
					        def mutate_and_get_payload(cls, input, context, info):
 | 
				
			||||||
 | 
					            files = context.FILES
 | 
				
			||||||
 | 
					            print(files)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # do something with files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return UploadFile(success=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,7 +78,7 @@ We should receive:
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
InputFields and InputObjectTypes
 | 
					InputFields and InputObjectTypes
 | 
				
			||||||
----------------------
 | 
					----------------------------------
 | 
				
			||||||
InputFields are used in mutations to allow nested input data for mutations
 | 
					InputFields are used in mutations to allow nested input data for mutations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To use an InputField you define an InputObjectType that specifies the structure of your input data
 | 
					To use an InputField you define an InputObjectType that specifies the structure of your input data
 | 
				
			||||||
| 
						 | 
					@ -114,7 +114,7 @@ Note that  **name** and **age** are part of **person_data** now
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Using the above mutation your new query would look like this:
 | 
					Using the above mutation your new query would look like this:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. code:: graphql
 | 
					.. code:: json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mutation myFirstMutation {
 | 
					    mutation myFirstMutation {
 | 
				
			||||||
        createPerson(personData: {name:"Peter", age: 24}) {
 | 
					        createPerson(personData: {name:"Peter", age: 24}) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user