File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Resources/doc/definitions Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ ### Upload files
2
+
3
+ here an example of how uploading can be done using this bundle
4
+
5
+ * First define schema
6
+ ``` yaml
7
+ RootMutation :
8
+ type : object
9
+ config :
10
+ fields :
11
+ uploadFile :
12
+ builder : " Relay::Mutation"
13
+ builderConfig :
14
+ inputType : UploadFileInput
15
+ payloadType : UploadFilePayload
16
+ mutateAndGetPayload : ' @=mutation("App\\GraphQL\\Mutation\\UploadMutation", [serv("request_stack"), value["title"]])'
17
+
18
+ UploadFilePayload :
19
+ type : relay-mutation-payload
20
+ config :
21
+ fields :
22
+ files : {type: "[String!]!" }
23
+
24
+ UploadFileInput :
25
+ type : relay-mutation-input
26
+ config :
27
+ fields :
28
+ title : {type: "String!"}
29
+ ` ` `
30
+
31
+ * here what the mutation look like
32
+
33
+ ` ` ` php
34
+ <?php
35
+
36
+ namespace App\GraphQL\Mutation;
37
+
38
+ use Overblog\GraphQLBundle\Error\UserError;
39
+ use Symfony\Component\HttpFoundation\Request;
40
+
41
+ class UploadMutation
42
+ {
43
+ public function __invoke(Request $request, $title)
44
+ {
45
+ /** @var \Symfony\Component\HttpFoundation\FileBag; $requestFiles */
46
+ $requestFiles = $request->files;
47
+ if (!$requestFiles->has('myFile')) {
48
+ throw new UserError('File "myFile" is required.');
49
+ }
50
+ /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
51
+ $file = $requestFiles->get('myFile');
52
+
53
+ // here do some work on your uploaded file
54
+
55
+ return [$title];
56
+ }
57
+ }
58
+ ```
You can’t perform that action at this time.
0 commit comments