Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Generator/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\UnionType;
use Murtukov\PHPCodeGenerator\ArrowFunction;
Expand Down Expand Up @@ -329,6 +330,10 @@ protected function buildConfig(array $config): Collection
$configLoader->addItem('resolveType', $this->buildResolveType($c->resolveType));
}

if (isset($c->isTypeOf)) {
$configLoader->addItem('isTypeOf', $this->buildIsTypeOf($c->isTypeOf));
}

if (isset($c->resolveField)) {
$configLoader->addItem('resolveField', $this->buildResolve($c->resolveField));
}
Expand Down Expand Up @@ -923,6 +928,30 @@ protected function buildResolveType($resolveType)
return $resolveType;
}

/**
* Builds an arrow function from a string with an expression prefix,
* otherwise just returns the provided value back untouched.
*
* Render example:
*
* fn($className) => (($className = "App\\ClassName") && $value instanceof $className)
*
* @param mixed $isTypeOf
*/
private function buildIsTypeOf($isTypeOf): ArrowFunction
{
if (EL::isStringWithTrigger($isTypeOf)) {
$expression = $this->expressionConverter->convert($isTypeOf);

return ArrowFunction::new(Literal::new($expression), 'bool')
->setStatic()
->addArguments('value', 'context')
->addArgument('info', ResolveInfo::class);
}

return ArrowFunction::new($isTypeOf);
}

/**
* Creates and array from a formatted string.
*
Expand Down