From 2d6996ebc84427f027c820675d3668013484d63a Mon Sep 17 00:00:00 2001 From: Bastian Date: Thu, 1 Sep 2016 11:50:14 +0200 Subject: [PATCH] BUGFIX: Support multiple variable formats Currently the only format the HTTP endpoint support for the variables is a JSON-serialized string: ``` { "query": "", "variables": "{\"id\": \"123\"}" // ... } ``` With this change, unserialized JSON objects are supported, too: ``` ``` { "query": "", "variables": { "id": "123" } // ... } ``` Note: I couldn't find anything about this in the GraphQL spec. The GraphiQL IDE sends the variables serialized, but other endpoints seem to support both formats. --- Classes/Controller/StandardController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/StandardController.php b/Classes/Controller/StandardController.php index 0902030..8e0087d 100644 --- a/Classes/Controller/StandardController.php +++ b/Classes/Controller/StandardController.php @@ -43,7 +43,7 @@ public function indexAction($endpoint) /** * @param string $endpoint The GraphQL endpoint, to allow for providing multiple APIs (this value is set from the routing usually) * @param string $query The GraphQL query string (see GraphQL::execute()) - * @param string $variables JSON-encoded list of variables (if any, see GraphQL::execute()) + * @param array $variables list of variables (if any, see GraphQL::execute()). Note: The variables can be JSON-serialized to a string (like GraphiQL does) or a "real" array * @param string $operationName The operation to execute (if multiple, see GraphQL::execute()) * @return string * @Flow\SkipCsrfProtection @@ -51,13 +51,15 @@ public function indexAction($endpoint) public function queryAction($endpoint, $query, $variables = null, $operationName = null) { $this->verifySettings($endpoint); - $decodedVariables = json_decode($variables, true); + if ($variables !== null && is_string($this->request->getArgument('variables'))) { + $variables = json_decode($this->request->getArgument('variables'), true); + } $querySchema = $this->typeResolver->get($this->settings['endpoints'][$endpoint]['querySchema']); $mutationSchema = isset($this->settings['endpoints'][$endpoint]['mutationSchema']) ? $this->typeResolver->get($this->settings['endpoints'][$endpoint]['mutationSchema']) : null; $subscriptionSchema = isset($this->settings['endpoints'][$endpoint]['subscriptionSchema']) ? $this->typeResolver->get($this->settings['endpoints'][$endpoint]['subscriptionSchema']) : null; $schema = new Schema($querySchema, $mutationSchema, $subscriptionSchema); - $result = GraphQL::executeAndReturnResult($schema, $query, null, $decodedVariables, $operationName); + $result = GraphQL::executeAndReturnResult($schema, $query, null, $variables, $operationName); $this->view->assign('result', $result); }