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/) 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). 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 ## [3.0.0] - 2022-07-04
### Modifications ### Modifications

View File

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

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

@ -0,0 +1 @@
vendor

View File

@ -7,7 +7,7 @@
} }
], ],
"require": { "require": {
"php": "^7.4", "php": ">=7.4",
"datatourisme/api": "^3.0" "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": case "POST":
if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] === 'application/json') { if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] === 'application/json') {
$rawBody = file_get_contents('php://input'); $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 { } else {
$requestData = $_POST; $requestData = $_POST;
} }
break; break;
case "GET": case "GET":
$requestData = $_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; break;
default: default:
exit; exit;
} }
$payload = isset($requestData['query']) ? $requestData['query'] : null; $payload = isset($requestData['query']) ? $requestData['query'] : null;
$variables = !empty($requestData['variables']) ? $requestData['variables'] : [];
require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/../vendor/autoload.php';
$processor = \Datatourisme\Api\DatatourismeApi::create('http://blazegraph:9999/blazegraph/namespace/kb/sparql'); $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'); header('Content-Type: application/json');
echo json_encode($response); echo json_encode($response);
exit; exit;