1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12:00

Add invalid query exception

This commit is contained in:
Jake Barnby 2022-07-14 15:57:51 +12:00
parent 4ee7f80433
commit 4f5c7ddada
3 changed files with 11 additions and 0 deletions

View file

@ -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.',

View file

@ -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;

View file

@ -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 = '';