diff --git a/src/Type/Definition/Argument.php b/src/Type/Definition/Argument.php index ce874b410..771b83475 100644 --- a/src/Type/Definition/Argument.php +++ b/src/Type/Definition/Argument.php @@ -60,14 +60,18 @@ public function __construct(array $config) } /** - * @phpstan-param ArgumentListConfig $config + * @phpstan-param ArgumentListConfig|callable(): ArgumentListConfig $config * * @return array */ - public static function listFromConfig(iterable $config): array + public static function listFromConfig($config): array { $list = []; + if (\is_callable($config)) { + $config = $config(); + } + foreach ($config as $name => $argConfig) { if (! \is_array($argConfig)) { $argConfig = ['type' => $argConfig]; diff --git a/src/Type/Definition/FieldDefinition.php b/src/Type/Definition/FieldDefinition.php index c36f76275..3d2193766 100644 --- a/src/Type/Definition/FieldDefinition.php +++ b/src/Type/Definition/FieldDefinition.php @@ -21,7 +21,7 @@ * name: string, * type: FieldType, * resolve?: FieldResolver|null, - * args?: ArgumentListConfig|null, + * args?: ArgumentListConfig|callable(): ArgumentListConfig|null, * description?: string|null, * visible?: VisibilityFn|bool, * deprecationReason?: string|null, @@ -31,7 +31,7 @@ * @phpstan-type UnnamedFieldDefinitionConfig array{ * type: FieldType, * resolve?: FieldResolver|null, - * args?: ArgumentListConfig|null, + * args?: ArgumentListConfig|callable(): ArgumentListConfig|null, * description?: string|null, * visible?: VisibilityFn|bool, * deprecationReason?: string|null, diff --git a/tests/Type/LazyDefinitionTest.php b/tests/Type/LazyDefinitionTest.php index f2efa1367..967b4c7c3 100644 --- a/tests/Type/LazyDefinitionTest.php +++ b/tests/Type/LazyDefinitionTest.php @@ -221,4 +221,24 @@ public function testLazyRootTypesNull(): void self::assertNull($schema->getMutationType()); self::assertNull($schema->getSubscriptionType()); } + + public function testLazyArgs(): void + { + $objType = new ObjectType([ + 'name' => 'SomeObject', + 'fields' => [ + 'f' => [ + 'type' => Type::string(), + 'args' => static fn (): array => [ + 'id' => ['type' => Type::int()], + ], + ], + ], + ]); + + $objType->assertValid(); + + self::assertNotNull($objType->getField('f')->getArg('id')); + self::assertSame(Type::int(), $objType->getField('f')->getArg('id')->getType()); + } }