Skip to content

Commit

Permalink
fix: remove entity typename = ref typename (#19)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tarekul authored Aug 31, 2021
1 parent 1c2bf7b commit e195b5d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/Types/EntityObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions test/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,28 @@ public function testResolvingEntityReferences()
{
$schema = StarWarsSchema::getEpisodesSchema();


$query = '
query GetEpisodes($representations: [_Any!]!) {
query GetEpisodes($representations: [_Any!]!) {
_entities(representations: $representations) {
... on Episode {
id
title
}
}
}
}
';

$variables = [
'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());
}
Expand Down
4 changes: 3 additions & 1 deletion test/StarWarsSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
]);
}
Expand Down

0 comments on commit e195b5d

Please sign in to comment.