ynloultratech /
graphql-bundle
| 1 | <?php |
||
| 2 | /******************************************************************************* |
||
| 3 | * This file is part of the GraphQL Bundle package. |
||
| 4 | * |
||
| 5 | * (c) YnloUltratech <[email protected]> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | ******************************************************************************/ |
||
| 10 | |||
| 11 | namespace Ynlo\GraphQLBundle\Request; |
||
| 12 | |||
| 13 | use Symfony\Component\HttpFoundation\Request; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Middleware to support "GraphQL multipart request specification" |
||
| 17 | * |
||
| 18 | * @see https://github.com/jaydenseric/graphql-multipart-request-spec |
||
| 19 | */ |
||
| 20 | class MultiPartFileUploadMiddleware implements RequestMiddlewareInterface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * {@inheritdoc} |
||
| 24 | */ |
||
| 25 | public function processRequest(Request $request, ExecuteQuery $query): void |
||
| 26 | { |
||
| 27 | //TODO: add support for batching |
||
| 28 | if (mb_stripos($request->headers->get('Content-Type'), 'multipart/form-data') !== false) { |
||
| 29 | if (($operations = $request->get('operations')) && ($map = $request->get('map'))) { |
||
| 30 | $result = json_decode($operations, true); |
||
| 31 | $map = json_decode($map, true); |
||
| 32 | foreach ($map as $fileKey => $locations) { |
||
| 33 | foreach ($locations as $location) { |
||
| 34 | $items = &$result; |
||
| 35 | foreach (explode('.', $location) as $key) { |
||
| 36 | if (!isset($items[$key]) || !is_array($items[$key])) { |
||
| 37 | $items[$key] = []; |
||
| 38 | } |
||
| 39 | $items = &$items[$key]; |
||
| 40 | } |
||
| 41 | |||
| 42 | $items = $request->files->get($fileKey); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | $query->setRequestString($result['query'] ?? null); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 47 | $query->setVariables($result['variables'] ?? []); |
||
| 48 | $query->setOperationName($result['operationName'] ?? null); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 |