You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/annotations/annotations-reference.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -591,13 +591,15 @@ class Hero {
591
591
592
592
This annotation is used on _class_ to define a GraphQL interface.
593
593
594
-
Required attributes:
594
+
Optional attributes:
595
595
596
596
-**resolveType** : An expression to resolve the types
597
+
-**name** : The GraphQL name of the interface (default to the class name without namespace)
597
598
598
-
Optional attributes:
599
+
If the `resolveType` attribute is not set, the service `overblog_graphql.interface_type_resolver` will be used to try to resolve the type automatically based on types implementing the interface and their associated class.
600
+
The system will register a map of interfaces with the list of types and their associated class name implementing the interface (the parameter is named `overblog_graphql_types.interfaces_map` in the container) and use it to resolve the type from the value (the first type where the class `instanceof` operator returns true will be used).
599
601
600
-
-**name** : The GraphQL name of the interface (default to the class name without namespace)
if (!isset($this->interfacesMap[$interfaceType])) {
21
+
thrownewUnresolvableException(sprintf('Default interface type resolver was unable to find interface with name "%s"', $interfaceType));
22
+
}
23
+
24
+
$gqlType = null;
25
+
$types = $this->interfacesMap[$interfaceType];
26
+
foreach ($typesas$className => $type) {
27
+
if ($valueinstanceof$className) {
28
+
$gqlType = $type;
29
+
break;
30
+
}
31
+
}
32
+
33
+
if (null === $gqlType) {
34
+
thrownewUnresolvableException(sprintf('Default interface type resolver with interface "%s" did not find a matching instance in: %s', $interfaceType, implode(', ', array_keys($types))));
0 commit comments