fix: add variables support

This commit is contained in:
blaise 2022-12-08 18:33:41 +01:00
parent 0b5fc57fde
commit b21d9ec57f
6 changed files with 1170 additions and 3 deletions

View File

@ -4,6 +4,11 @@ Tous les changements notables apportés à ce projet seront documentés dans ce
Le format est basé sur [Keep a Changelog](http://keepachangelog.com/fr/1.0.0/)
et ce projet adhère à [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [3.1.0] - 2022-12-08
### Corrections
- Support des variables dans le point d'accès GraphQL
## [3.0.0] - 2022-07-04
### Modifications

View File

@ -18,6 +18,7 @@ RUN \
php -r "unlink('composer-setup.php');"
# install vendors
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN php composer.phar install
# run server

1
docker/app/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
vendor

View File

@ -7,7 +7,7 @@
}
],
"require": {
"php": "^7.4",
"php": ">=7.4",
"datatourisme/api": "^3.0"
}
}

1144
docker/app/composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,24 +11,40 @@ switch($_SERVER['REQUEST_METHOD']) {
case "POST":
if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] === 'application/json') {
$rawBody = file_get_contents('php://input');
$requestData = json_decode($rawBody ?: '', true);
try {
$requestData = json_decode($rawBody ?: '', true, 512, JSON_THROW_ON_ERROR);
} catch(\JsonException $e) {
http_response_code(400);
echo json_encode(['errors' => [['message' => $e->getMessage()]]]);
exit;
}
} else {
$requestData = $_POST;
}
break;
case "GET":
$requestData = $_GET;
if (isset($requestData['variables'])) {
try {
$requestData['variables'] = json_decode($requestData['variables'], true, 512, JSON_THROW_ON_ERROR);
} catch(\JsonException $e) {
http_response_code(400);
echo json_encode(['errors' => [['message' => 'variables : ' . $e->getMessage()]]]);
exit;
}
}
break;
default:
exit;
}
$payload = isset($requestData['query']) ? $requestData['query'] : null;
$variables = !empty($requestData['variables']) ? $requestData['variables'] : [];
require_once __DIR__.'/../vendor/autoload.php';
$processor = \Datatourisme\Api\DatatourismeApi::create('http://blazegraph:9999/blazegraph/namespace/kb/sparql');
$response = $processor->process($payload);
$response = $processor->process($payload, $variables);
header('Content-Type: application/json');
echo json_encode($response);
exit;