From ae7ae54dfa82acbfb42d082efe737140acd90682 Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Wed, 25 Sep 2019 14:07:46 +0200 Subject: [PATCH] Detect args passed to directive without args (fixes #63) --- README.md | 2 +- .../validation/rules/known_argument_names.py | 2 +- tests/validation/test_known_argument_names.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a00f7dc..dc1a1b08 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The current version 3.0.0b0 of GraphQL-core is up-to-date with GraphQL.js version 14.5.0. All parts of the API are covered by an extensive test suite -of currently 1981 unit tests. +of currently 1983 unit tests. ## Documentation diff --git a/src/graphql/validation/rules/known_argument_names.py b/src/graphql/validation/rules/known_argument_names.py index c98e2104..178bca27 100644 --- a/src/graphql/validation/rules/known_argument_names.py +++ b/src/graphql/validation/rules/known_argument_names.py @@ -60,7 +60,7 @@ def __init__(self, context: Union[ValidationContext, SDLValidationContext]) -> N def enter_directive(self, directive_node: DirectiveNode, *_args): directive_name = directive_node.name.value known_args = self.directive_args.get(directive_name) - if directive_node.arguments and known_args: + if directive_node.arguments and known_args is not None: for arg_node in directive_node.arguments: arg_name = arg_node.name.value if arg_name not in known_args: diff --git a/tests/validation/test_known_argument_names.py b/tests/validation/test_known_argument_names.py index 03d76d69..ac3c8bb0 100644 --- a/tests/validation/test_known_argument_names.py +++ b/tests/validation/test_known_argument_names.py @@ -120,6 +120,25 @@ def field_args_are_invalid(): [unknown_directive_arg("unless", "skip", [], 3, 25)], ) + def directive_without_args_is_valid(): + assert_valid( + """ + { + dog @onField + } + """ + ) + + def arg_passed_to_directive_without_args_is_reported(): + assert_errors( + """ + { + dog @onField(if: true) + } + """, + [unknown_directive_arg("if", "onField", [], 3, 30)], + ) + def misspelled_directive_args_are_reported(): assert_errors( """