-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
44 lines (35 loc) · 1.17 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization");
header("Access-Control-Allow-Credentials: true");
($_SERVER['REQUEST_METHOD'] === 'OPTIONS') ? exit(http_response_code(200)) : null;
require 'vendor/autoload.php';
require 'types.php';
include 'includes/autoloader.php';
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
try {
$types = getGraphQLTypes();
$schema = new Schema([
'query' => $types['queryType'],
'mutation' => $types['mutationType']
]);
$rawInput = file_get_contents('php://input');
$input = json_decode($rawInput, true);
$query = $input['query'];
$variableValues = isset($input['variables']) ? $input['variables'] : null;
$rootValue = [];
$result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues);
$output = $result->toArray();
} catch (\Exception $e) {
$output = [
'errors' => [
[
'message' => $e->getMessage()
]
]
];
}
header('Content-Type: application/json');
echo json_encode($output);