File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,12 @@ def validate_directives(self) -> None:
154154 # Ensure they are named correctly.
155155 self .validate_name (directive )
156156
157+ if not directive .locations :
158+ self .report_error (
159+ f"Directive @{ directive .name } must include 1 or more locations." ,
160+ directive .ast_node ,
161+ )
162+
157163 # Ensure the arguments are valid.
158164 for arg_name , arg in directive .args .items ():
159165 # Ensure they are named correctly.
Original file line number Diff line number Diff line change @@ -440,6 +440,21 @@ def rejects_a_schema_whose_directives_are_incorrectly_typed():
440440 {"message" : "Expected directive but got: SomeScalar." },
441441 ]
442442
443+ def rejects_a_schema_whose_directives_have_empty_locations ():
444+ bad_directive = GraphQLDirective (
445+ name = "BadDirective1" ,
446+ locations = [],
447+ )
448+ schema = GraphQLSchema (
449+ SomeObjectType ,
450+ directives = [bad_directive ],
451+ )
452+ assert validate_schema (schema ) == [
453+ {
454+ "message" : "Directive @BadDirective1 must include 1 or more locations." ,
455+ },
456+ ]
457+
443458
444459def describe_type_system_root_types_must_all_be_different_if_provided ():
445460 def accepts_a_schema_with_different_root_types ():
You can’t perform that action at this time.
0 commit comments