@@ -15,7 +15,7 @@ In order to upload a single file, you need to:
15
15
16
16
* set the file as a variable value in the mutation
17
17
* create a :class: `FileVar <gql.FileVar> ` object with your file path
18
- * provide the `FileVar ` instance to the `variable_values ` argument of ` execute `
18
+ * provide the `FileVar ` instance to the `variable_values ` attribute of your query
19
19
* set the `upload_files ` argument to True
20
20
21
21
.. code-block :: python
@@ -37,11 +37,9 @@ In order to upload a single file, you need to:
37
37
}
38
38
''' )
39
39
40
- params = {" file" : FileVar(" YOUR_FILE_PATH" )}
40
+ query.variable_values = {" file" : FileVar(" YOUR_FILE_PATH" )}
41
41
42
- result = client.execute(
43
- query, variable_values = params, upload_files = True
44
- )
42
+ result = client.execute(query, upload_files = True )
45
43
46
44
Setting the content-type
47
45
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -97,11 +95,9 @@ It is also possible to upload multiple files using a list.
97
95
f1 = FileVar(" YOUR_FILE_PATH_1" )
98
96
f2 = FileVar(" YOUR_FILE_PATH_2" )
99
97
100
- params = {" files" : [f1, f2]}
98
+ query.variable_values = {" files" : [f1, f2]}
101
99
102
- result = client.execute(
103
- query, variable_values = params, upload_files = True
104
- )
100
+ result = client.execute(query, upload_files = True )
105
101
106
102
107
103
Streaming
@@ -150,11 +146,9 @@ setting the `streaming` argument of :class:`FileVar <gql.FileVar>` to `True`
150
146
streaming = True ,
151
147
)
152
148
153
- params = {" file" : f1}
149
+ query.variable_values = {" file" : f1}
154
150
155
- result = client.execute(
156
- query, variable_values = params, upload_files = True
157
- )
151
+ result = client.execute(query, upload_files = True )
158
152
159
153
Another option is to use an async generator to provide parts of the file.
160
154
@@ -172,11 +166,9 @@ to read the files in chunks and create this asynchronous generator.
172
166
yield chunk
173
167
174
168
f1 = FileVar(file_sender(file_name = ' YOUR_FILE_PATH' ))
175
- params = {" file" : f1}
169
+ query.variable_values = {" file" : f1}
176
170
177
- result = client.execute(
178
- query, variable_values = params, upload_files = True
179
- )
171
+ result = client.execute(query, upload_files = True )
180
172
181
173
Streaming downloaded files
182
174
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -193,7 +185,7 @@ In order to do that, you need to:
193
185
194
186
* get the response from an aiohttp request and then get the StreamReader instance
195
187
from `resp.content `
196
- * provide the StreamReader instance to the `variable_values ` argument of ` execute `
188
+ * provide the StreamReader instance to the `variable_values ` attribute of your query
197
189
198
190
Example:
199
191
@@ -204,7 +196,7 @@ Example:
204
196
async with http_client.get(' YOUR_DOWNLOAD_URL' ) as resp:
205
197
206
198
# We now have a StreamReader instance in resp.content
207
- # and we provide it to the variable_values argument of execute
199
+ # and we provide it to the variable_values attribute of the query
208
200
209
201
transport = AIOHTTPTransport(url = ' YOUR_GRAPHQL_URL' )
210
202
@@ -218,8 +210,6 @@ Example:
218
210
}
219
211
''' )
220
212
221
- params = {" file" : FileVar(resp.content)}
213
+ query.variable_values = {" file" : FileVar(resp.content)}
222
214
223
- result = client.execute(
224
- query, variable_values = params, upload_files = True
225
- )
215
+ result = client.execute(query, upload_files = True )
0 commit comments