Skip to content

Include directives in SchemaPrinter output #552

Description

@franzwilding

Hey!

I'm currently playing around with a custom schema builder, that allows registering classes that extend the schema and eventually create a cacheable DocumentNode. It is working pretty well, my current solution looks like this:

    /**
     * @return DocumentNode
     * @throws \GraphQL\Error\Error
     * @throws \GraphQL\Error\SyntaxError
     */
    public function buildCacheableSchema() : DocumentNode {

        $schema = BuildSchema::build(self::BASE_SCHEMA);

        foreach($this->extenders as $extender) {
            if($extension = $extender->extend($schema)) {
                $schema = SchemaExtender::extend($schema, Parser::parse($extender->extend($schema)));
            }
        }

        return Parser::parse(SchemaPrinter::doPrint($schema));
    }

However, I am facing the problem, that custom directives get lost during doPrint, because of the implementation of SchemaPrinter::printField which only includes deprecated directive .

Now my question consists of two parts:

  1. Is there a better solution to get the DocumentNode from a Schema, besides doing parse(doPrint(schema))?

  2. And if this actually is the best solution to do this, how do I get my custom directives into the final schema?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions