diff --git a/src/Type/Definition/Config.php b/src/Type/Definition/Config.php index 69ba068..e2b5660 100644 --- a/src/Type/Definition/Config.php +++ b/src/Type/Definition/Config.php @@ -21,6 +21,7 @@ class Config const REQUIRED = 65536; const KEY_AS_NAME = 131072; + const MAYBE_THUNK = 262144; private static $enableValidation = false; @@ -105,7 +106,11 @@ class Config if ($def->flags & self::REQUIRED === 0 && $value === null) { return ; } - Utils::invariant(is_array($value), $err, 'array'); + if (($def->flags & self::MAYBE_THUNK) > 0) { + Utils::invariant(is_array($value) || is_callable($value), $err, 'array or callable'); + } else { + Utils::invariant(is_array($value), $err, 'array'); + } if (!empty($def->isMap)) { if ($def->flags & self::KEY_AS_NAME) { diff --git a/src/Type/Definition/InputObjectType.php b/src/Type/Definition/InputObjectType.php index 88de86e..d5cdb4f 100644 --- a/src/Type/Definition/InputObjectType.php +++ b/src/Type/Definition/InputObjectType.php @@ -21,7 +21,7 @@ class InputObjectType extends Type implements InputType 'type' => Config::INPUT_TYPE | Config::REQUIRED, 'defaultValue' => Config::ANY, 'description' => Config::STRING - ], Config::KEY_AS_NAME), + ], Config::KEY_AS_NAME | Config::MAYBE_THUNK), 'description' => Config::STRING ]); diff --git a/src/Type/Definition/InterfaceType.php b/src/Type/Definition/InterfaceType.php index c7e470c..5192149 100644 --- a/src/Type/Definition/InterfaceType.php +++ b/src/Type/Definition/InterfaceType.php @@ -55,7 +55,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT 'name' => Config::STRING, 'fields' => Config::arrayOf( FieldDefinition::getDefinition(), - Config::KEY_AS_NAME + Config::KEY_AS_NAME | Config::MAYBE_THUNK ), 'resolveType' => Config::CALLBACK, // function($value, ResolveInfo $info) => ObjectType 'description' => Config::STRING diff --git a/src/Type/Definition/ObjectType.php b/src/Type/Definition/ObjectType.php index 5fd211b..675bcce 100644 --- a/src/Type/Definition/ObjectType.php +++ b/src/Type/Definition/ObjectType.php @@ -79,11 +79,12 @@ class ObjectType extends Type implements OutputType, CompositeType 'name' => Config::STRING | Config::REQUIRED, 'fields' => Config::arrayOf( FieldDefinition::getDefinition(), - Config::KEY_AS_NAME + Config::KEY_AS_NAME | Config::MAYBE_THUNK ), 'description' => Config::STRING, 'interfaces' => Config::arrayOf( - Config::INTERFACE_TYPE + Config::INTERFACE_TYPE, + Config::MAYBE_THUNK ), 'isTypeOf' => Config::CALLBACK, // ($value, ResolveInfo $info) => boolean 'resolveField' => Config::CALLBACK