Skip to content

SchemaDirectiveVisitor not called when extending objects. #344

Open
@wapiflapi

Description

@wapiflapi

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 extending 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededto do

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions