Skip to content

Commit

Permalink
Detect args passed to directive without args (fixes #63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Sep 25, 2019
1 parent 386ed9d commit ae7ae54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/validation/rules/known_argument_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions tests/validation/test_known_argument_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down

0 comments on commit ae7ae54

Please sign in to comment.