Skip to content

Commit e195b5d

Browse files
authored
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
1 parent 1c2bf7b commit e195b5d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/Types/EntityObjectType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ public function resolveReference($ref, $context = null, $info = null)
9797
$this->validateReferenceKeys($ref);
9898

9999
$entity = ($this->referenceResolver)($ref, $context, $info);
100-
101-
$entity['__typename'] = $ref['__typename'];
102-
100+
103101
return $entity;
104102
}
105103

test/SchemaTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,28 @@ public function testResolvingEntityReferences()
8686
{
8787
$schema = StarWarsSchema::getEpisodesSchema();
8888

89+
8990
$query = '
90-
query GetEpisodes($representations: [_Any!]!) {
91+
query GetEpisodes($representations: [_Any!]!) {
9192
_entities(representations: $representations) {
9293
... on Episode {
9394
id
9495
title
9596
}
96-
}
97+
}
9798
}
9899
';
99100

100101
$variables = [
101102
'representations' => [
102103
[
103104
'__typename' => 'Episode',
104-
'id' => 1
105+
'id' => 1,
105106
]
106107
]
107108
];
108109

109110
$result = GraphQL::executeQuery($schema, $query, null, null, $variables);
110-
111111
$this->assertCount(1, $result->data['_entities']);
112112
$this->assertMatchesSnapshot($result->toArray());
113113
}

test/StarWarsSchema.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ private static function getEpisodeType(): EntityObjectType
8989
'keyFields' => ['id'],
9090
'__resolveReference' => function ($ref) {
9191
// print_r($ref);
92-
return StarWarsData::getEpisodeById($ref['id']);
92+
$entity = StarWarsData::getEpisodeById($ref['id']);
93+
$entity["__typename"] = "Episode";
94+
return $entity;
9395
}
9496
]);
9597
}

0 commit comments

Comments
 (0)