Skip to content

Commit ba9e3e2

Browse files
authored
Fix style for examples/00-hello-world (#829)
1 parent ccd11f6 commit ba9e3e2

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

examples/00-hello-world/graphql.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
// Test this using following command
36
// php -S localhost:8080 ./graphql.php &
47
// curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
58
// curl http://localhost:8080 -d '{"query": "mutation { sum(x: 2, y: 2) }" }'
69
require_once __DIR__ . '/../../vendor/autoload.php';
710

11+
use GraphQL\GraphQL;
812
use GraphQL\Type\Definition\ObjectType;
913
use GraphQL\Type\Definition\Type;
1014
use GraphQL\Type\Schema;
11-
use GraphQL\GraphQL;
1215

1316
try {
1417
$queryType = new ObjectType([
@@ -19,9 +22,9 @@
1922
'args' => [
2023
'message' => ['type' => Type::string()],
2124
],
22-
'resolve' => function ($rootValue, $args) {
25+
'resolve' => static function ($rootValue, array $args): string {
2326
return $rootValue['prefix'] . $args['message'];
24-
}
27+
},
2528
],
2629
],
2730
]);
@@ -35,7 +38,7 @@
3538
'x' => ['type' => Type::int()],
3639
'y' => ['type' => Type::int()],
3740
],
38-
'resolve' => function ($calc, $args) {
41+
'resolve' => static function ($calc, array $args): int {
3942
return $args['x'] + $args['y'];
4043
},
4144
],
@@ -49,21 +52,21 @@
4952
'mutation' => $mutationType,
5053
]);
5154

52-
$rawInput = file_get_contents('php://input');
53-
$input = json_decode($rawInput, true);
54-
$query = $input['query'];
55-
$variableValues = isset($input['variables']) ? $input['variables'] : null;
55+
$rawInput = file_get_contents('php://input');
56+
$input = json_decode($rawInput, true);
57+
$query = $input['query'];
58+
$variableValues = $input['variables'] ?? null;
5659

5760
$rootValue = ['prefix' => 'You said: '];
58-
$result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues);
59-
$output = $result->toArray();
60-
} catch (\Exception $e) {
61+
$result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues);
62+
$output = $result->toArray();
63+
} catch (Throwable $e) {
6164
$output = [
6265
'error' => [
63-
'message' => $e->getMessage()
64-
]
66+
'message' => $e->getMessage(),
67+
],
6568
];
6669
}
70+
6771
header('Content-Type: application/json; charset=UTF-8');
6872
echo json_encode($output);
69-

phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<arg value="nps" />
1111

1212
<file>benchmarks</file>
13+
<file>examples/00-hello-world</file>
1314
<file>src</file>
1415
<file>tests</file>
1516

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55

66
paths:
77
- %currentWorkingDirectory%/benchmarks
8+
- %currentWorkingDirectory%/examples/00-hello-world
89
- %currentWorkingDirectory%/src
910
- %currentWorkingDirectory%/tests
1011

0 commit comments

Comments
 (0)