Skip to content

Commit ae7ae54

Browse files
committed
Detect args passed to directive without args (fixes #63)
1 parent 386ed9d commit ae7ae54

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current version 3.0.0b0 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.5.0.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 1981 unit tests.
19+
of currently 1983 unit tests.
2020

2121

2222
## Documentation

src/graphql/validation/rules/known_argument_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, context: Union[ValidationContext, SDLValidationContext]) -> N
6060
def enter_directive(self, directive_node: DirectiveNode, *_args):
6161
directive_name = directive_node.name.value
6262
known_args = self.directive_args.get(directive_name)
63-
if directive_node.arguments and known_args:
63+
if directive_node.arguments and known_args is not None:
6464
for arg_node in directive_node.arguments:
6565
arg_name = arg_node.name.value
6666
if arg_name not in known_args:

tests/validation/test_known_argument_names.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ def field_args_are_invalid():
120120
[unknown_directive_arg("unless", "skip", [], 3, 25)],
121121
)
122122

123+
def directive_without_args_is_valid():
124+
assert_valid(
125+
"""
126+
{
127+
dog @onField
128+
}
129+
"""
130+
)
131+
132+
def arg_passed_to_directive_without_args_is_reported():
133+
assert_errors(
134+
"""
135+
{
136+
dog @onField(if: true)
137+
}
138+
""",
139+
[unknown_directive_arg("if", "onField", [], 3, 30)],
140+
)
141+
123142
def misspelled_directive_args_are_reported():
124143
assert_errors(
125144
"""

0 commit comments

Comments
 (0)