Skip to content

Commit eb1ded2

Browse files
authored
Merge pull request #412 from BossGrand/master
Added documentation on how to accept files in a mutation
2 parents a3c3be2 + 0ed4050 commit eb1ded2

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

docs/relay/mutations.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,29 @@ subclass of ``relay.ClientIDMutation``.
2727
ship = create_ship(ship_name, faction_id)
2828
faction = get_faction(faction_id)
2929
return IntroduceShip(ship=ship, faction=faction)
30+
31+
32+
33+
Accepting Files
34+
-------------
35+
36+
Mutations can also accept files, they will be in the context variable.
37+
38+
.. code:: python
39+
40+
class UploadFile(graphene.ClientIDMutation):
41+
class Input:
42+
pass
43+
# nothing needed for uploading file
44+
45+
# your return fields
46+
success = graphene.String()
47+
48+
@classmethod
49+
def mutate_and_get_payload(cls, input, context, info):
50+
files = context.FILES
51+
print(files)
52+
53+
# do something with files
54+
55+
return UploadFile(success=True)

docs/types/mutations.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ We should receive:
7878
}
7979
8080
InputFields and InputObjectTypes
81-
----------------------
81+
----------------------------------
8282
InputFields are used in mutations to allow nested input data for mutations
8383

8484
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
114114

115115
Using the above mutation your new query would look like this:
116116

117-
.. code:: graphql
117+
.. code:: json
118118
119119
mutation myFirstMutation {
120120
createPerson(personData: {name:"Peter", age: 24}) {

0 commit comments

Comments
 (0)