Skip to content

Commit

Permalink
Fail the query with a helpful message if the variables defined do not…
Browse files Browse the repository at this point in the history
… match the expected values
  • Loading branch information
kinow committed Oct 12, 2020
1 parent 96f5603 commit 1b210b6
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions cylc/flow/network/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b210b6

Please sign in to comment.