From 1b210b6876aa7207fb62ed79c79bc45edad2bf17 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Tue, 6 Oct 2020 15:39:29 +1300 Subject: [PATCH] Fail the query with a helpful message if the variables defined do not match the expected values --- cylc/flow/network/graphql.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/cylc/flow/network/graphql.py b/cylc/flow/network/graphql.py index 0012d16dc8c..f0f7d721e28 100644 --- a/cylc/flow/network/graphql.py +++ b/cylc/flow/network/graphql.py @@ -150,14 +150,28 @@ def __init__(self, schema, document_ast, variable_values): for defn in document_ast.definitions: if isinstance(defn, ast.OperationDefinition): root_type = get_operation_root_type(schema, defn) + definition_variables = defn.variable_definitions or [] + variables = {} + if definition_variables: + variables = get_variable_values( + schema, + definition_variables, + variable_values + ) + # check if we are missing some of the definition variables + if not variables or \ + len(variables) != len(definition_variables): + variable_names = [ + v.variable.name.value for v in definition_variables + ] + msg = (f'Please check your query variables. The ' + f'following variables are expected: ' + f'[{", ".join(variable_names)}]') + raise ValueError(msg) self.operation_defs[getattr(defn.name, 'value', root_type)] = { 'definition': defn, 'parent_type': root_type, - 'variables': get_variable_values( - schema, - defn.variable_definitions or [], - variable_values - ), + 'variables': variables, } elif isinstance(defn, ast.FragmentDefinition): self.fragment_defs[defn.name.value] = defn