src/Rebing/GraphQL/GraphQLUploadMiddleware.php
private function parseUploadedFiles(Request $request)
    {
        $bodyParams = $request->all();
        if (!isset($bodyParams['map'])) {
            throw new RequestError('The request must define a `map`');
        }

        $map = json_decode($bodyParams['map'], true);
        $result = json_decode($bodyParams['operations'], true);
        if (isset($result['operationName'])) {
            $result['operation'] = $result['operationName'];
            unset($result['operationName']);
        }

        foreach ($map as $fileKey => $locations) {
            foreach ($locations as $location) {
                $items = &$result;
                foreach (explode('.', $location) as $key) {
                    if (!isset($items[$key]) || !is_array($items[$key])) {
                        $items[$key] = [];
                    }
                    $items = &$items[$key];
                }

                $items = $request->allFiles()[$fileKey];
            }
        }

        $request->replace($result);

        return $request;
    }
private function parseUploadedFiles(Request $request)
    {
        $bodyParams = $request->all();
        if (!isset($bodyParams['map'])) {
            throw new RequestError('The request must define a `map`');
        }

        $map = json_decode($bodyParams['map'], true);
        $result = json_decode($bodyParams['operations'], true);
        if (isset($result['operationName'])) {
            $result['operation'] = $result['operationName'];
            unset($result['operationName']);
        }

        foreach ($map as $fileKey => $locations) {
            foreach ($locations as $location) {
                $items = &$result;
                foreach (explode('.', $location) as $key) {
                    if (!isset($items[$key]) || !is_array($items[$key])) {
                        $items[$key] = [];
                    }
                    $items = &$items[$key];
                }

                $items = $request->allFiles()[$fileKey];
            }
        }

        $request->replace($result);

        return $request;
    }
private function parseUploadedFiles ( Request $ request ) { $ bodyParams = $ request -> all ( ) ; if ( ! isset ( $ bodyParams [ 'map' ] ) ) { throw new RequestError ( 'The request must define a `map`' ) ; } $ map = json_decode ( $ bodyParams [ 'map' ] , true ) ; $ result = json_decode ( $ bodyParams [ 'operations' ] , true ) ; if ( isset ( $ result [ 'operationName' ] ) ) { $ result [ 'operation' ] = $ result [ 'operationName' ] ; unset ( $ result [ 'operationName' ] ) ; } foreach ( $ map as $ fileKey => $ locations ) { foreach ( $ locations as $ location ) { $ items = & $ result ; foreach ( explode ( '.' , $ location ) as $ key ) { if ( ! isset ( $ items [ $ key ] ) || ! is_array ( $ items [ $ key ] ) ) { $ items [ $ key ] = [ ] ; } $ items = & $ items [ $ key ] ; } $ items = $ request -> allFiles ( ) [ $ fileKey ] ; } } $ request -> replace ( $ result ) ; return $ request ; }
Inject uploaded files defined in the 'map' key into the 'variables' key

@param  \Illuminate\Http\Request  $request

@return \Illuminate\Http\Request
Inject uploaded files defined in the map key into the variables key