mirumee/ariadne

SchemaDirectiveVisitor not called when extending objects.

开放

#344 创建于 2020年3月28日

 (5 条评论) (0 个反应) (0 位负责人)Python (195 个派生)batch import
bughelp wantedto do

仓库指标

星标
 (2,342 个星标)
PR 合并指标
 (平均合并 12天) (30 天内合并 3 个 PR)

描述

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.

贡献者指南