diff --git a/docs/getting-started.md b/docs/getting-started.md index d88a9d1..44f1940 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -82,10 +82,13 @@ $schema = new Schema([ ]); $rawInput = file_get_contents('php://input'); +$input = json_decode($rawInput, true); +$query = $input['query']; +$variableValues = isset($input['variables']) ? $input['variables'] : null; try { $rootValue = ['prefix' => 'You said: ']; - $result = GraphQL::execute($schema, $rawInput, $rootValue); + $result = GraphQL::execute($schema, $query, $rootValue, null, $variableValues); } catch (\Exception $e) { $result = [ 'error' => [ @@ -100,7 +103,7 @@ echo json_encode($result); Our example is ready. Try it by running: ```sh 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. diff --git a/examples/00-hello-world/README.md b/examples/00-hello-world/README.md index d4dded2..98a7393 100644 --- a/examples/00-hello-world/README.md +++ b/examples/00-hello-world/README.md @@ -9,10 +9,10 @@ php -S localhost:8080 ./graphql.php ### 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 ``` -curl http://localhost:8080 -d "mutation { sum(x: 2, y: 2) }" +curl http://localhost:8080 -d '{"query": "mutation { sum(x: 2, y: 2) }" }' ``` diff --git a/examples/00-hello-world/graphql.php b/examples/00-hello-world/graphql.php index 450089e..cb9e84f 100644 --- a/examples/00-hello-world/graphql.php +++ b/examples/00-hello-world/graphql.php @@ -48,9 +48,12 @@ try { ]); $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: ']; - $result = GraphQL::execute($schema, $rawInput, $rootValue); + $result = GraphQL::execute($schema, $query, $rootValue, null, $variableValues); } catch (\Exception $e) { $result = [ 'error' => [