diff --git a/public/API/graphql.php b/public/API/graphql.php index cec07bc..0e8190a 100644 --- a/public/API/graphql.php +++ b/public/API/graphql.php @@ -11,25 +11,16 @@ $schema = new Schema([ 'query' => $queryType ]); -$rawInput = file_get_contents('php://input'); -$input = json_decode($rawInput, true); -$query = $input['query']; -$variableValues = isset($input['variables']) ? $input['variables'] : null; - try { - $rootValue = [ - "db"=> $conn - ]; - $result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues); - $output = $result->toArray(); -} catch (\Exception $e) { - $output = [ - 'errors' => [ - [ - 'message' => $e->getMessage() - ] + $serverConfig = [ + 'schema' => $schema, + 'rootValue' => [ + 'db' =>$conn, ] ]; + $server = new StandardServer($serverConfig); + + $server->handleRequest(); +} catch (Throwable $error) { + StandardServer::send500Error($error); } -header('Content-Type: application/json'); -echo json_encode($output); \ No newline at end of file