|
16 | 16 | use GraphQL\Error\DebugFlag; |
17 | 17 |
|
18 | 18 | // Disable default PHP error reporting - we have better one for debug mode (see bellow) |
19 | | -ini_set('display_errors', 0); |
| 19 | +ini_set('display_errors', '0'); |
20 | 20 |
|
21 | | -$debug = false; |
| 21 | +$debug = DebugFlag::NONE; |
22 | 22 | if (!empty($_GET['debug'])) { |
23 | | - set_error_handler(function ($severity, $message, $file, $line) use (&$phpErrors) { |
| 23 | + set_error_handler(function ($severity, $message, $file, $line) { |
24 | 24 | throw new ErrorException($message, 0, $severity, $file, $line); |
25 | 25 | }); |
26 | 26 | $debug = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE; |
|
33 | 33 | // Prepare context that will be available in all field resolvers (as 3rd argument): |
34 | 34 | $appContext = new AppContext(); |
35 | 35 | $appContext->viewer = ''; |
36 | | - $appContext->rootUrl = $_SERVER['REQUEST_URI']; |
| 36 | + $appContext->rootUrl = $_SERVER['REQUEST_URI']; // @phpstan-ignore assign.propertyType |
37 | 37 | $appContext->request = $_REQUEST; |
38 | 38 |
|
39 | 39 | // Parse incoming query and variables |
40 | | - if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { |
| 40 | + if (isset($_SERVER['CONTENT_TYPE']) && is_string($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { |
41 | 41 | $raw = file_get_contents('php://input') ?: ''; |
42 | | - $data = json_decode($raw, true); |
43 | | - } |
44 | | - |
45 | | - if (is_null($data)) { |
| 42 | + $data = (array)json_decode($raw, true); |
| 43 | + } else { |
46 | 44 | $data = $appContext->request; |
47 | 45 | } |
48 | 46 |
|
|
53 | 51 |
|
54 | 52 | $result = GraphQL::executeQuery( |
55 | 53 | $schema, |
56 | | - $data['query'], |
| 54 | + $data['query'], // @phpstan-ignore argument.type |
57 | 55 | null, |
58 | 56 | $appContext, |
59 | | - array_key_exists('variables', $data) ? $data['variables'] : [] |
| 57 | + array_key_exists('variables', $data) ? $data['variables'] : [] // @phpstan-ignore argument.type |
60 | 58 | ); |
61 | 59 | $output = $result->toArray($debug); |
62 | 60 | $httpStatus = 200; |
63 | 61 | } catch (\Exception $error) { |
64 | 62 | $httpStatus = 500; |
65 | | - $output['errors'] = [ |
| 63 | + $errors = [ |
66 | 64 | FormattedError::createFromException($error, $debug) |
67 | 65 | ]; |
| 66 | + |
| 67 | + if (isset($output) && is_array($output)) { |
| 68 | + $output['errors'] = $errors; |
| 69 | + } else { |
| 70 | + $output = [ |
| 71 | + 'errors' => $errors |
| 72 | + ]; |
| 73 | + } |
68 | 74 | } |
69 | 75 |
|
70 | 76 | header('Content-Type: application/json', true, $httpStatus); |
|
0 commit comments