Skip to content

Commit 948deaa

Browse files
raise-error-when-directive-declaration-is-missing
1 parent bc32076 commit 948deaa

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ariadne/schema_visitor.py

+9
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,15 @@ def _add_directive(decl):
468468

469469
each(schema.directives, _add_directive)
470470

471+
missing_directives = [
472+
name for name in directive_visitors if name not in declared_directives
473+
]
474+
475+
if missing_directives:
476+
raise ValueError(
477+
f"Missing directive declarations for: {', '.join(missing_directives)}"
478+
)
479+
471480
# If the visitor subclass overrides get_directive_declaration, and it
472481
# returns a non-null GraphQLDirective, use that instead of any directive
473482
# declared in the schema itself. Reasoning: if a SchemaDirectiveVisitor

tests/test_directives.py

+15
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ def test_directive_raises_type_error_if_required_argument_is_not_given():
178178
make_executable_schema(type_defs, directives={"test": ReturnValueDirective})
179179

180180

181+
def test_directive_raises_type_error_if_there_is_typo():
182+
type_defs = """
183+
directive @test on FIELD_DEFINITION
184+
185+
type Query {
186+
hello: String! @test,
187+
}
188+
"""
189+
190+
with pytest.raises(ValueError):
191+
make_executable_schema(
192+
type_defs, directives={"test_typo": ReturnValueDirective}
193+
)
194+
195+
181196
def test_can_implement_unique_id_directive():
182197
type_defs = """
183198
directive @uniqueID(name: String, from: [String]) on OBJECT

0 commit comments

Comments
 (0)