Skip to content

Commit c01f0a3

Browse files
feat: separate logics for preparing type resolver
1 parent 5eb5ff9 commit c01f0a3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/RootFieldsResolver.php

+12-9
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,26 @@ private function resolve(ResolveInfo $info): Promise
6868
{
6969
$type = $info->returnType;
7070

71+
$this->prepareTypeResolver($type);
72+
73+
$promise = $this->delegatedPromises[$info->operation];
74+
75+
return $promise->then(fn (ExecutionResult $result) => $this->accessResultByPath($info->path, $result));
76+
}
77+
78+
private function prepareTypeResolver(Type $type): void
79+
{
7180
if ($type instanceof WrappingType) {
7281
$type = $type->getInnermostType();
7382
}
7483

7584
if ($type instanceof AbstractType) {
76-
$type->config['resolveType'] ??= $this->resolveAbstractType(...);
85+
$type->config['resolveType'] = $this->resolveAbstractType(...);
7786
}
7887

7988
if ($type instanceof ObjectType) {
80-
$type->resolveFieldFn ??= $this->resolveObjectFields(...);
89+
$type->resolveFieldFn = $this->resolveObjectFields(...);
8190
}
82-
83-
$promise = $this->delegatedPromises[$info->operation];
84-
85-
return $promise->then(fn (ExecutionResult $result) => $this->accessResultByPath($info->path, $result));
8691
}
8792

8893
private function resolveAbstractType(array $value, mixed $context, ResolveInfo $info): Type
@@ -105,9 +110,7 @@ private function resolveAbstractType(array $value, mixed $context, ResolveInfo $
105110

106111
$implType = $info->schema->getType($typename);
107112

108-
if ($implType instanceof ObjectType) {
109-
$implType->resolveFieldFn = $this->resolveObjectFields(...);
110-
}
113+
$this->prepareTypeResolver($implType);
111114

112115
/// If impl type is not object, executor should throw error.
113116
return $implType;

0 commit comments

Comments
 (0)