Skip to content

Commit

Permalink
Fix Node resource type conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain committed Apr 26, 2020
1 parent 19ac419 commit 5f7115c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 151 deletions.
21 changes: 0 additions & 21 deletions features/bootstrap/DoctrineContext.php
Expand Up @@ -71,7 +71,6 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeLabel;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositePrimitiveItem;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Container;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedBoolean;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedDate;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedInteger;
Expand Down Expand Up @@ -107,7 +106,6 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Greeting;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\MaxDepthDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Node;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Order;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Person;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\PersonToPet;
Expand Down Expand Up @@ -1051,25 +1049,6 @@ public function thereIsAnAnswerToTheQuestion(string $a, string $q)
$this->manager->clear();
}

/**
* @Given there are :nb nodes in a container :uuid
*/
public function thereAreNodesInAContainer(int $nb, string $uuid)
{
$container = new Container();
$container->setId($uuid);
$this->manager->persist($container);

for ($i = 0; $i < $nb; ++$i) {
$node = new Node();
$node->setContainer($container);
$node->setSerial($i);
$this->manager->persist($node);
}

$this->manager->flush();
}

/**
* @Then the password :password for user :user should be hashed
*/
Expand Down
3 changes: 3 additions & 0 deletions src/GraphQl/Type/TypeConverter.php
Expand Up @@ -108,6 +108,9 @@ private function getResourceType(Type $type, bool $input, ?string $queryName, ?s
if (null === $resourceMetadata->getGraphql()) {
return null;
}
if ('Node' === $resourceMetadata->getShortName()) {
throw new \UnexpectedValueException('A "Node" resource cannot be used with GraphQL because the type is already used by the Relay specification.');
}
} catch (ResourceClassNotFoundException $e) {
// Skip objects that are not resources for now
return null;
Expand Down
68 changes: 0 additions & 68 deletions tests/Fixtures/TestBundle/Entity/Container.php

This file was deleted.

62 changes: 0 additions & 62 deletions tests/Fixtures/TestBundle/Entity/Node.php

This file was deleted.

13 changes: 13 additions & 0 deletions tests/GraphQl/Type/TypeConverterTest.php
Expand Up @@ -96,6 +96,19 @@ public function testConvertTypeNoGraphQlResourceMetadata(): void
$this->assertNull($graphqlType);
}

public function testConvertTypeNodeResource(): void
{
$type = new Type(Type::BUILTIN_TYPE_OBJECT, false, 'node');

$this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
$this->resourceMetadataFactoryProphecy->create('node')->shouldBeCalled()->willReturn((new ResourceMetadata('Node'))->withGraphql(['test']));

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('A "Node" resource cannot be used with GraphQL because the type is already used by the Relay specification.');

$this->typeConverter->convertType($type, false, null, null, 'resourceClass', 'rootClass', null, 0);
}

public function testConvertTypeResourceClassNotFound(): void
{
$type = new Type(Type::BUILTIN_TYPE_OBJECT, false, 'dummy');
Expand Down

0 comments on commit 5f7115c

Please sign in to comment.