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; } ]); }