### Resolver
The resolver is basically a call back function for each field. There is always a default resolver for all fields, when we define own resolve function for a field, we simply override the default resolver.
### How to define Schema for Query
1 2 3 4 5 | $schema_obj = new Schema { "query" => $queryType, "mutation" => $mutationType, "subscription" => $subscriptionType } |
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | require_once __DIR__ . '/vendor/autoload.php' ; use GraphQL\GraphQL; use GraphQL\Type\Schema; try { $schema_obj = new Schema([ 'query' => $queryType ]); $Input = file_get_contents ( 'php://input' ); $input_data = json_decode( $Input , true); $query_data = $input_data [ 'query' ]; $variable_values = isset( $input_data [ 'variables' ]) ? $input_data [ 'variables' ] : null; $value = [ 'prefix' => 'Output: ' ]; $resultant = GraphQL::executeQuery( $schema_obj , $query_data , $value , null, $variable_values ); $output_value = $resultant ->toArray(); } catch (\Exception $e ){ $output_value = [ 'errors' => [ [ 'message' => $e ->getMessage() ] ] ]; } header( 'Content-Type: application/json' ); echo json_encode( $output_value ); |
$ curl http://192.168.34.10:8000 -d ‘{“query”: “query { echo(message: \” Hi Knowband, this is my first GraphQL program \”) }” }’
{“errors”:[{“message”:”Schema does not define the required query root type.”,”extensions”:{“category”:”graphql”},”locations”:[{“line”:1,”column”:1}]}]}
うむ… 実践的にやらないとあかんな