Completed
Push — master ( f446c9...f7ee24 )
by Rafael
04:05
created

StandardGraphQLRequestMiddleware::processRequest()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 9
cts 10
cp 0.9
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 9
nop 2
crap 5.025
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
 * Request middleware compatible with "express" server format:
17
 * @see https://github.com/graphql/express-graphql
18
 */
19
class StandardGraphQLRequestMiddleware implements RequestMiddlewareInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 22
    public function processRequest(Request $request, ExecuteQuery $query): void
25
    {
26 22
        $content = $request->getContent();
27 22
        if ($content) {
28 22
            $input = json_decode($content, true);
29 22
            if (isset($input['query'])) {
30 22
                $query->setRequestString($input['query']);
31
            }
32
33 22
            if (isset($input['variables'])) {
34 22
                $query->setVariables($input['variables']);
35
            }
36
37 22
            if (isset($input['operationName'])) {
38
                $query->setOperationName($input['operationName']);
39
            }
40
        }
41 22
    }
42
}
43