-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail the query with a helpful message if the variables defined do not match the expected values #3856
Conversation
Virtual memory error when running the bash tests in the Docker container. Fix available in #3854 Will spend some more time on this later trying to add a test. Not sure if a unit test will work, might try our new test classes for the first time 👍 |
The other PR that contains the fix for the Docker builds may take a while to be merged, while we wait for GH Actions to include Python 3.9. So I've cherry-picked the commit that should fix Docker, and pushed here 👍 |
e2c9cde
to
577e8fa
Compare
Functional test broadcast/00-simple is failing, but I think it needs to be updated after this fix (just need to understand how it works, and confirm it indeed just needs to be updated) |
577e8fa
to
1b210b6
Compare
Added a unit test, and the changelog. Confirmed locally with Existing functional tests cover that function already, though partially. |
I fixed the functional test in this PR, and yesterday it passed in the Docker image. Strangely, it failed now, but my only updates were changelog and a new unit test. 🤔 ready for review, I think the test is just a bit brittle in Docker (will investigate why later) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'll defer to @dwsutherland for the definitive review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea @kinow , may I suggest the following instead:
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 []
if definition_variables:
def_var_names = {
v.variable.name.value
for v in definition_variables
}
var_names_diff = def_var_names.difference({
k
for k in variable_values
if k in def_var_names
})
# check if we are missing some of the definition variables
if var_names_diff:
msg = (f'Please check your query variables. The '
f'following variables are missing: '
f'[{", ".join(var_names_diff)}]')
raise ValueError(msg)
self.operation_defs[getattr(defn.name, 'value', root_type)] = {
'definition': defn,
'parent_type': root_type,
'variables': get_variable_values(
schema,
definition_variables,
variable_values
),
}
elif isinstance(defn, ast.FragmentDefinition):
self.fragment_defs[defn.name.value] = defn
Then you don't have to change the default behaviour of GraphQL (i.e. if None
is desirable to fall to the schema defined default), and hence not have to change the CLI tests.
Hi @dwsutherland ! Thanks for the suggestion! I will just need some time tomorrow to re-contextualize with the change, and understand your change. Then it should be a matter of just updating the PR with a new/edit commit, and check if tests pass 👍 Might be able to complete it before the executive roadshow starts tomorrow in Auckland, by the morning. |
… match the expected values
2871380
to
b140920
Compare
Fixed git conflicts, and applied @dwsutherland 's patch (thanks!). I think we now just need to wait for CI to verify. |
b140920
to
e1a23f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go 👍
These changes close #3855
Requirements check-list
CONTRIBUTING.md
and added my name as a Code Contributor.