Skip to content

Commit

Permalink
Fix object input field shortcut as callable
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincz committed Feb 5, 2021
1 parent 115a20e commit 4b5354e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,9 @@ Deprecates:
Refactoring:
- Reify AST node types and remove unneeded nullability (#751)

Fix:
- Fix Input Object field shortcut definition with callable (#773)

#### 14.4.1

Fix:
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Definition/InputObjectType.php
Expand Up @@ -87,7 +87,7 @@ protected function initializeFields() : void
}

foreach ($fields as $name => $field) {
if ($field instanceof Type) {
if ($field instanceof Type || is_callable($field)) {
$field = ['type' => $field];
}
$field = new InputObjectField($field + ['name' => $name]);
Expand Down
17 changes: 17 additions & 0 deletions tests/Type/DefinitionTest.php
Expand Up @@ -1608,6 +1608,23 @@ public function testAcceptsAnInputObjectTypeWithAFieldFunction() : void
self::assertSame(Type::string(), $inputObjType->getField('f')->getType());
}

/**
* @see it('accepts an Input Object type with a field type function')
*/
public function testAcceptsAnInputObjectTypeWithAFieldTypeFunction() : void
{
$inputObjType = new InputObjectType([
'name' => 'SomeInputObject',
'fields' => [
'f' => static function () : Type {
return Type::string();
},
],
]);
$inputObjType->assertValid();
self::assertSame(Type::string(), $inputObjType->getField('f')->getType());
}

/**
* @see it('rejects an Input Object type with incorrect fields')
*/
Expand Down

0 comments on commit 4b5354e

Please sign in to comment.