Skip to content

Commit 7049ca2

Browse files
authored
Merge pull request #847 from mfn/mfn-interface-fix
Finalize "Fix 'TypeNotFound' when an interface defined after another type where it is used"
2 parents 628034b + 9aaf8f3 commit 7049ca2

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ CHANGELOG
132132
- Make it easier to extend select fields [\#799 / crissi](https://github.com/rebing/graphql-laravel/pull/799)
133133
- The `$args` argument, of the `handle` method of the execution middlewares requires `array` as type [\#843 / sforward](https://github.com/rebing/graphql-laravel/pull/843)
134134

135+
### Fixed
136+
- Fix `TypeNotFound` when an interface defined after another type where it is used [\#828 / kasian-sergeev](https://github.com/rebing/graphql-laravel/pull/828)
135137

136138
### Removed
137139
- The method `\Rebing\GraphQL\GraphQLServiceProvider::provides` was removed [\#769 / mfn](https://github.com/rebing/graphql-laravel/pull/769)\

src/Support/Type.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,15 @@ public function getFields(): array
9797
public function getAttributes(): array
9898
{
9999
$attributes = $this->attributes();
100-
$interfaces = $this->interfaces();
101100

102-
$attributes = array_merge($this->attributes, [
101+
return array_merge($this->attributes, [
103102
'fields' => function () {
104103
return $this->getFields();
105104
},
105+
'interfaces' => function () {
106+
return $this->interfaces();
107+
},
106108
], $attributes);
107-
108-
if ($interfaces) {
109-
$attributes['interfaces'] = $interfaces;
110-
}
111-
112-
return $attributes;
113109
}
114110

115111
/**

tests/Database/SelectFields/InterfaceTests/InterfaceTest.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ protected function getEnvironmentSetUp($app): void
2626
]);
2727

2828
$app['config']->set('graphql.types', [
29+
CommentType::class,
2930
ExampleInterfaceType::class,
30-
InterfaceImpl1Type::class,
3131
ExampleRelationType::class,
32-
LikableInterfaceType::class,
32+
InterfaceImpl1Type::class,
33+
LikeType::class,
3334
PostType::class,
34-
CommentType::class,
3535
UserType::class,
36-
LikeType::class,
36+
// Interface deliberately last to guaranteed lazy loading them
37+
// works, otherwise tests without the fix in 9644b66faa8d37e7a1c36969470504614ab1c766
38+
// won't work!
39+
LikableInterfaceType::class,
3740
]);
3841
}
3942

tests/Unit/TypeTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ public function testGetAttributesFieldsClosure(): void
4747
$attributes['fields']();
4848
}
4949

50+
public function testGetAttributesInterfacesClosure(): void
51+
{
52+
$type = $this->getMockBuilder(ExampleType::class)
53+
->onlyMethods(['interfaces'])
54+
->getMock();
55+
56+
$type->expects(self::once())
57+
->method('interfaces');
58+
59+
$attributes = $type->getAttributes();
60+
$attributes['interfaces']();
61+
}
62+
5063
public function testToArray(): void
5164
{
5265
$type = new ExampleType();

0 commit comments

Comments
 (0)