Description
It seems like custom directives do not work on extend type Object
, this might be by design but I could not find anywhere in the Ariadne docs or GraphQL specs something that confirms this.
Here is a simple test case:
from ariadne import QueryType, gql, make_executable_schema, SchemaDirectiveVisitor
from ariadne.asgi import GraphQL
class TestDirective(SchemaDirectiveVisitor):
def visit_object(self, object_):
print(f"Visiting object {object_}")
return object_
type_defs = gql("""
directive @test on OBJECT
type Query {
foo: String!
}
extend type Query @test {
bar: String!
}
""")
query = QueryType()
schema = make_executable_schema(type_defs, query, directives={"test": TestDirective})
app = GraphQL(schema, debug=True)
Testing using uvicorn --debug test:app
.
I expect Visiting object Query
to be printed but it looks like the SchemaDirectiveVisitor
is not called when extend
ing objects. (But it works as expected when doing type Query @test
.)
If this is not a bug, it would make sense to at least output a warning or error that using directives on extended objects is not supported.
Looking at the code (which I do not know well), I suspect that build_and_extend_schema(ast_document)
is called before SchemaDirectiveVisitor.visit_schema_directives(schema, directives)
and that it somehow loses the directives in the process of extending?
To be honest I expected the directives to be applied before the schema is extended, but that's just my gut feeling.