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 #1053

Closed sb-onoffice-de closed 2 years ago

sb-onoffice-de commented 2 years ago

Hello!

We're using version 14.11.3.

Assuming this piece of code:

<?php

namespace onOffice\GraphQL;

use PHPUnit\Framework\TestCase;
use GraphQL\GraphQL;
use GraphQL\Utils\BuildSchema;

class RepeatableDirectivesTest extends TestCase
{
    public function testRepeatableDirectives()
    {
        $schema =  /* @lang GraphQL */ <<< GRAPHQL
directive @foo(bar: Int) repeatable on OBJECT

type Baz @foo(bar: 1) @foo(bar: 2) {
    id: ID!
}

type Query {
    baz: Baz
}
GRAPHQL;

        $result = GraphQL::executeQuery(BuildSchema::build($schema), 'query { baz { id }');

        $this->assertNull($result->data);
    }
}

It says:

GraphQL\Error\Error: The directive "foo" can only be used once at this location.

I believe it's a problem in Validator/Rules/UniqueDirectivesPerLocation.php. If I change that

if (! isset($uniqueDirectiveMap[$directiveName]))

to

if (! isset($uniqueDirectiveMap[$directiveName]) ||
    $uniqueDirectiveMap[$directiveName])

it seems to be working, but I don't know whether this is the right fix.

Stefan

spawnia commented 2 years ago

This should be fixed as of 14.6.2, see https://github.com/webonyx/graphql-php/commit/bcbb6926bbf2d0cf466c63d0b9edc90e44d5dd3f

sb-onoffice-de commented 2 years ago

Is 14.6.2 newer than 14.11.3 that we're using? Or could you give me a hint where to look at?

spawnia commented 2 years ago

Fixed with https://github.com/webonyx/graphql-php/releases/tag/v14.11.4

sb-onoffice-de commented 2 years ago

Thank you!