@@ -61,6 +61,60 @@ public static function delegate(
61
61
}
62
62
}
63
63
64
+ private function prepareType (Type $ type ): void
65
+ {
66
+ if ($ type instanceof WrappingType) {
67
+ $ type = $ type ->getInnermostType ();
68
+ }
69
+
70
+ if (isset ($ this ->preparedTypes [$ type ])) {
71
+ return ;
72
+ }
73
+
74
+ if ($ type instanceof ObjectType) {
75
+ foreach ($ type ->getFields () as $ fieldDef ) {
76
+ /** @var FieldDefinition $fieldDef */
77
+ $ fieldDef ->resolveFn = $ this ->resolve (...);
78
+ }
79
+
80
+ $ type ->resolveFieldFn = null ;
81
+ }
82
+
83
+ if ($ type instanceof AbstractType) {
84
+ $ resolveType = fn (array $ value , mixed $ context , ResolveInfo $ info ) => $ this ->resolveAbstractType (
85
+ $ type ,
86
+ $ value ,
87
+ $ context ,
88
+ $ info ,
89
+ );
90
+
91
+ $ type ->config ['resolveType ' ] = $ resolveType ;
92
+ }
93
+
94
+ $ this ->preparedTypes [$ type ] = true ;
95
+ }
96
+
97
+ private function resolveAbstractType (AbstractType $ abstractType , array $ value , mixed $ context , ResolveInfo $ info ): Type
98
+ {
99
+ /// __typename field should be existed in $value
100
+ /// because we have added it to delegated query
101
+ $ typename = $ value [Introspection::TYPE_NAME_FIELD_NAME ];
102
+
103
+ if (!$ info ->schema ->hasType ($ typename )) {
104
+ throw new LogicException (
105
+ sprintf ('Expect type: `%s` implementing `%s` should be exist in schema ' , $ typename , $ abstractType )
106
+ );
107
+ }
108
+
109
+ $ implType = $ info ->schema ->getType ($ typename );
110
+
111
+ assert ($ implType instanceof ObjectType);
112
+
113
+ $ this ->prepareType ($ implType );
114
+
115
+ return $ implType ;
116
+ }
117
+
64
118
private function resolve (mixed $ value , array $ args , mixed $ context , ResolveInfo $ info ): Promise
65
119
{
66
120
$ promise = $ this ->delegatedPromises [$ info ->operation ] ??= $ this ->delegateToExecute (
@@ -120,60 +174,6 @@ function (ExecutionResult $result): ExecutionResult {
120
174
);
121
175
}
122
176
123
- private function prepareType (Type $ type ): void
124
- {
125
- if ($ type instanceof WrappingType) {
126
- $ type = $ type ->getInnermostType ();
127
- }
128
-
129
- if (isset ($ this ->preparedTypes [$ type ])) {
130
- return ;
131
- }
132
-
133
- if ($ type instanceof ObjectType) {
134
- foreach ($ type ->getFields () as $ fieldDef ) {
135
- /** @var FieldDefinition $fieldDef */
136
- $ fieldDef ->resolveFn = $ this ->resolve (...);
137
- }
138
-
139
- $ type ->resolveFieldFn = null ;
140
- }
141
-
142
- if ($ type instanceof AbstractType) {
143
- $ resolveType = fn (array $ value , mixed $ context , ResolveInfo $ info ) => $ this ->resolveAbstractType (
144
- $ type ,
145
- $ value ,
146
- $ context ,
147
- $ info ,
148
- );
149
-
150
- $ type ->config ['resolveType ' ] = $ resolveType ;
151
- }
152
-
153
- $ this ->preparedTypes [$ type ] = true ;
154
- }
155
-
156
- private function resolveAbstractType (AbstractType $ abstractType , array $ value , mixed $ context , ResolveInfo $ info ): Type
157
- {
158
- /// __typename field should be existed in $value
159
- /// because we have added it to delegated query
160
- $ typename = $ value [Introspection::TYPE_NAME_FIELD_NAME ];
161
-
162
- if (!$ info ->schema ->hasType ($ typename )) {
163
- throw new LogicException (
164
- sprintf ('Expect type: `%s` implementing `%s` should be exist in schema ' , $ typename , $ abstractType )
165
- );
166
- }
167
-
168
- $ implType = $ info ->schema ->getType ($ typename );
169
-
170
- assert ($ implType instanceof ObjectType);
171
-
172
- $ this ->prepareType ($ implType );
173
-
174
- return $ implType ;
175
- }
176
-
177
177
/**
178
178
* @throws Error
179
179
*/
0 commit comments