From 4f5c7ddada1b450560fde816934ee5db839fa45d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 14 Jul 2022 15:57:51 +1200 Subject: [PATCH] Add invalid query exception --- app/config/errors.php | 5 +++++ app/controllers/api/graphql.php | 4 ++++ src/Appwrite/Extend/Exception.php | 2 ++ 3 files changed, 11 insertions(+) diff --git a/app/config/errors.php b/app/config/errors.php index 8464d9b150..d9de78895f 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -517,6 +517,11 @@ return [ 'description' => 'Query is required.', 'code' => 400, ], + Exception::GRAPHQL_INVALID_QUERY => [ + 'name' => Exception::GRAPHQL_NO_QUERY, + 'description' => 'Invalid query supplied.', + 'code' => 400, + ], Exception::GRAPHQL_TOO_MANY_QUERIES => [ 'name' => Exception::GRAPHQL_TOO_MANY_QUERIES, 'description' => 'Too many queries have been sent in the same request.', diff --git a/app/controllers/api/graphql.php b/app/controllers/api/graphql.php index 92545c6553..0750412732 100644 --- a/app/controllers/api/graphql.php +++ b/app/controllers/api/graphql.php @@ -88,6 +88,10 @@ function graphqlRequest( if (\count($query) > $maxBatchSize) { throw new Exception('Too many queries.', 400, Exception::GRAPHQL_TOO_MANY_QUERIES); } + foreach ($query as $item) { + if (!isset($item['query'])) { + throw new Exception('Invalid query.', 400, Exception::GRAPHQL_INVALID_QUERY); + } } $debugFlags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE; diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 5ee67c87a9..177271bf49 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -173,6 +173,8 @@ class Exception extends \Exception /** GraphqQL */ public const GRAPHQL_NO_QUERY = 'graphql_no_query'; + public const GRAPHQL_INVALID_QUERY = 'graphql_invalid_query'; + public const GRAPHQL_TOO_MANY_QUERIES = 'graphql_too_many_queries'; private $type = '';