### 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
$schema_obj = new Schema {
"query" => $queryType,
"mutation" => $mutationType,
"subscription" => $subscriptionType
}
index.php
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}]}]}
うむ… 実践的にやらないとあかんな