webonyx / graphql-php

PHP implementation of the GraphQL specification based on the reference implementation in JavaScript
https://webonyx.github.io/graphql-php
MIT License
4.63k stars 561 forks source link

Repeatable directives with SchemaExtender #1056

Closed sb-onoffice-de closed 2 years ago

sb-onoffice-de commented 2 years ago

Hello!

I think we've found another issue with repeatable directives, it seems that SchemaExtender is losing the isRepeatable property:

<?php

namespace onOffice\GraphQL;

use GraphQL\Language\Parser;
use GraphQL\Utils\SchemaExtender;
use PHPUnit\Framework\TestCase;
use GraphQL\Utils\BuildSchema;

class RepeatableDirectivesWithSchemaExtenderTest extends TestCase
{
    public function testRepeatableDirectives()
    {
        $definition = /* @lang GraphQL */ <<< GRAPHQL
directive @foo repeatable on OBJECT

type Query {
    bar: Int
}
GRAPHQL;

        $extension = /* @lang GraphQL */ <<< GRAPHQL
extend type Query
{
    baz: Int
}
GRAPHQL;

        $schema = BuildSchema::build($definition);
        $this->assertTrue($schema->getConfig()->directives[0]->isRepeatable);

        $extendedSchema = SchemaExtender::extend($schema, Parser::parse($extension));
        $this->assertTrue($extendedSchema->getConfig()->directives[0]->isRepeatable);
    }
}

Digging the code I think that adding of

'isRepeatable' => $directive->isRepeatable,

in SchemaExternder::extendDirective seems to fix this problem.

Stefan

spawnia commented 2 years ago

Can you create a pull request with a failing test case and subsequent fix?

sb-onoffice-de commented 2 years ago

I found out that it is fixed in master, but not in the 14.x branch, see #931

spawnia commented 2 years ago

Backported with https://github.com/webonyx/graphql-php/releases/tag/v14.11.5

sb-onoffice-de commented 2 years ago

Thank you!