File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,10 @@ protected function buildConfig(array $config): Collection
329329 $ configLoader ->addItem ('resolveType ' , $ this ->buildResolveType ($ c ->resolveType ));
330330 }
331331
332+ if (isset ($ c ->isTypeOf )) {
333+ $ configLoader ->addItem ('isTypeOf ' , $ this ->buildIsTypeOf ($ c ->isTypeOf ));
334+ }
335+
332336 if (isset ($ c ->resolveField )) {
333337 $ configLoader ->addItem ('resolveField ' , $ this ->buildResolve ($ c ->resolveField ));
334338 }
@@ -923,6 +927,32 @@ protected function buildResolveType($resolveType)
923927 return $ resolveType ;
924928 }
925929
930+ /**
931+ * Builds an arrow function from a string with an expression prefix,
932+ * otherwise just returns the provided value back untouched.
933+ *
934+ * Render example:
935+ *
936+ * fn($className) => (($className = "App\\ClassName") && $value instanceof $className)
937+ *
938+ * @param mixed $isTypeOf
939+ *
940+ * @return mixed|ArrowFunction
941+ */
942+ private function buildIsTypeOf ($ isTypeOf )
943+ {
944+ if (EL ::isStringWithTrigger ($ isTypeOf )) {
945+ $ expression = $ this ->expressionConverter ->convert ($ isTypeOf );
946+
947+ return ArrowFunction::new ()
948+ ->addArguments ('className ' )
949+ ->setExpression (Literal::new ($ expression ))
950+ ->setStatic ();
951+ }
952+
953+ return $ isTypeOf ;
954+ }
955+
926956 /**
927957 * Creates and array from a formatted string.
928958 *
You can’t perform that action at this time.
0 commit comments