mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56:05 +03:00
Make Hello World compatible with GraphiQL
This allow newcomers to follow documentation to get started and then keep exploring with GraphiQL Closes #87
This commit is contained in:
parent
ac5c518cbe
commit
5ca69c6ec8
@ -82,10 +82,13 @@ $schema = new Schema([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$rawInput = file_get_contents('php://input');
|
$rawInput = file_get_contents('php://input');
|
||||||
|
$input = json_decode($rawInput, true);
|
||||||
|
$query = $input['query'];
|
||||||
|
$variableValues = isset($input['variables']) ? $input['variables'] : null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$rootValue = ['prefix' => 'You said: '];
|
$rootValue = ['prefix' => 'You said: '];
|
||||||
$result = GraphQL::execute($schema, $rawInput, $rootValue);
|
$result = GraphQL::execute($schema, $query, $rootValue, null, $variableValues);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$result = [
|
$result = [
|
||||||
'error' => [
|
'error' => [
|
||||||
@ -100,7 +103,7 @@ echo json_encode($result);
|
|||||||
Our example is ready. Try it by running:
|
Our example is ready. Try it by running:
|
||||||
```sh
|
```sh
|
||||||
php -S localhost:8000 graphql.php
|
php -S localhost:8000 graphql.php
|
||||||
curl http://localhost:8000 -d "query { echo(message: \"Hello World\") }"
|
curl http://localhost:8000 -d '{"query": "query { echo(message: \"Hello World\") }" }'
|
||||||
```
|
```
|
||||||
|
|
||||||
Check out the full [source code](https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world) of this example.
|
Check out the full [source code](https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world) of this example.
|
||||||
|
@ -9,10 +9,10 @@ php -S localhost:8080 ./graphql.php
|
|||||||
|
|
||||||
### Try query
|
### Try query
|
||||||
```
|
```
|
||||||
curl http://localhost:8080 -d "query { echo(message: \"Hello World\") }"
|
curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Try mutation
|
### Try mutation
|
||||||
```
|
```
|
||||||
curl http://localhost:8080 -d "mutation { sum(x: 2, y: 2) }"
|
curl http://localhost:8080 -d '{"query": "mutation { sum(x: 2, y: 2) }" }'
|
||||||
```
|
```
|
||||||
|
@ -48,9 +48,12 @@ try {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$rawInput = file_get_contents('php://input');
|
$rawInput = file_get_contents('php://input');
|
||||||
|
$input = json_decode($rawInput, true);
|
||||||
|
$query = $input['query'];
|
||||||
|
$variableValues = isset($input['variables']) ? $input['variables'] : null;
|
||||||
|
|
||||||
$rootValue = ['prefix' => 'You said: '];
|
$rootValue = ['prefix' => 'You said: '];
|
||||||
$result = GraphQL::execute($schema, $rawInput, $rootValue);
|
$result = GraphQL::execute($schema, $query, $rootValue, null, $variableValues);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$result = [
|
$result = [
|
||||||
'error' => [
|
'error' => [
|
||||||
|
Loading…
Reference in New Issue
Block a user