Skip to content

Commit

Permalink
fix: Disable entity keys validation (#22)
Browse files Browse the repository at this point in the history
* fix: Do not validate entity keys

* test: Fix tests
  • Loading branch information
ldiego08 authored Oct 14, 2021
1 parent 61772cc commit 2b418ba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
5 changes: 0 additions & 5 deletions src/Types/EntityObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ private function validateReferenceResolver()
private function validateReferenceKeys($ref)
{
Utils::invariant(isset($ref['__typename']), 'Type name must be provided in the reference.');

$refKeys = array_keys($ref);
$refContainsKeys = !empty(array_intersect($this->getKeyFields(), $refKeys));

Utils::invariant($refContainsKeys, 'Key fields are missing from the entity reference.');
}

public static function validateResolveReference(array $config)
Expand Down
50 changes: 0 additions & 50 deletions test/EntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,56 +86,6 @@ public function testResolvingEntityReference()
$this->assertEquals($expectedRef, $actualRef);
}

public function testResolvingEntityReferenceWithoutAllKeys()
{
$expectedRef = [
'id' => 1,
'email' => '[email protected]',
'firstName' => 'Luke',
'lastName' => 'Skywalker',
'__typename' => 'User'
];

$userType = new EntityObjectType([
'name' => 'User',
'keyFields' => ['id', 'email'],
'fields' => [
'id' => ['type' => Type::int()],
'email' => ['type' => Type::string()],
'firstName' => ['type' => Type::string()],
'lastName' => ['type' => Type::string()]
],
'__resolveReference' => function () use ($expectedRef) {
return $expectedRef;
}
]);

$actualRef = $userType->resolveReference(['email' => '[email protected]', '__typename' => 'User']);

$this->assertEquals($expectedRef, $actualRef);
}

public function testResolvingEntityReferenceWithoutAnyKeys()
{
$userType = new EntityObjectType([
'name' => 'User',
'keyFields' => ['id', 'email'],
'fields' => [
'id' => ['type' => Type::int()],
'email' => ['type' => Type::string()],
'firstName' => ['type' => Type::string()],
'lastName' => ['type' => Type::string()]
],
'__resolveReference' => function () {
return null;
}
]);

$this->expectException(InvariantViolation::class);

$userType->resolveReference(['__typename' => 'User']);
}

public function testCreatingEntityRefType()
{
$userTypeKeyFields = ['id', 'email'];
Expand Down

0 comments on commit 2b418ba

Please sign in to comment.