From e195b5d93a7e8053e9d58af459641d3d33f8beae Mon Sep 17 00:00:00 2001 From: Tarek Islam Date: Tue, 31 Aug 2021 16:52:44 -0400 Subject: [PATCH] fix: remove entity typename = ref typename (#19) * fix:remove entity typename = ref typename * fix:reverted back to see if errors are gone * Fix:removed entity typename = ref typename * removed tests for resolvingEntitiesToRef and testForCustomerResolver because they fail without entity object having an typename * fix:Readded test for referenceResolver and added typename to entity in getEpisodeType * fix: put back previously deleted test * refactor: made code to create entity shorter --- src/Types/EntityObjectType.php | 4 +--- test/SchemaTest.php | 8 ++++---- test/StarWarsSchema.php | 4 +++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Types/EntityObjectType.php b/src/Types/EntityObjectType.php index de233c6..03aca9e 100644 --- a/src/Types/EntityObjectType.php +++ b/src/Types/EntityObjectType.php @@ -97,9 +97,7 @@ public function resolveReference($ref, $context = null, $info = null) $this->validateReferenceKeys($ref); $entity = ($this->referenceResolver)($ref, $context, $info); - - $entity['__typename'] = $ref['__typename']; - + return $entity; } diff --git a/test/SchemaTest.php b/test/SchemaTest.php index d51e69a..8f9b882 100644 --- a/test/SchemaTest.php +++ b/test/SchemaTest.php @@ -86,14 +86,15 @@ public function testResolvingEntityReferences() { $schema = StarWarsSchema::getEpisodesSchema(); + $query = ' - query GetEpisodes($representations: [_Any!]!) { + query GetEpisodes($representations: [_Any!]!) { _entities(representations: $representations) { ... on Episode { id title } - } + } } '; @@ -101,13 +102,12 @@ public function testResolvingEntityReferences() 'representations' => [ [ '__typename' => 'Episode', - 'id' => 1 + 'id' => 1, ] ] ]; $result = GraphQL::executeQuery($schema, $query, null, null, $variables); - $this->assertCount(1, $result->data['_entities']); $this->assertMatchesSnapshot($result->toArray()); } diff --git a/test/StarWarsSchema.php b/test/StarWarsSchema.php index 79e0d0c..5594896 100644 --- a/test/StarWarsSchema.php +++ b/test/StarWarsSchema.php @@ -89,7 +89,9 @@ private static function getEpisodeType(): EntityObjectType 'keyFields' => ['id'], '__resolveReference' => function ($ref) { // print_r($ref); - return StarWarsData::getEpisodeById($ref['id']); + $entity = StarWarsData::getEpisodeById($ref['id']); + $entity["__typename"] = "Episode"; + return $entity; } ]); }