@@ -332,8 +332,22 @@ query {
332332
333333## Promise mapping
334334
335- You can defer execution of fields by returning a callable. To specify the field type, add a ` @return ` PHPDoc annotation
336- with a return type, like so: ` @return callable(): YourTypeHere ` . The callable must not have any parameters.
335+ You can defer execution of fields by returning a ` Closure ` . To specify the field type, add a ` @return ` PHPDoc annotation
336+ with a return type, like so: ` @return Closure(): YourTypeHere ` . The closure must not have any parameters.
337+
338+ :::caution
339+
340+ Only ` Closure ` type is supported, which means that all of the following will work:
341+ - arrow functions: ` fn () => 123 `
342+ - anonymous functions: ` function () { return 123; } `
343+ - first-class callables: ` random_int(...) ` , ` Integer::random(...) ` etc
344+
345+ But other callables ** will not** :
346+ - callable strings: ` 'random_int' ` , ` 'Integer::random' `
347+ - callable arrays: ` [Integer::class, 'random'] ` , ` [$object, 'method'] `
348+ - invokable objects: ` new class { function __invoke() { return 123; } } `
349+
350+ :::
337351
338352An alternative way is to return ` \GraphQL\Deferred ` instances, along with specifying the type through the
339353` outputType ` parameter of field attributes: ` #[Field(outputType: SomeGQLType)] ` .
@@ -348,10 +362,10 @@ class Product
348362 // ...
349363
350364 /**
351- * @return callable (): string
365+ * @return Closure (): string
352366 */
353367 #[Field]
354- public function getName(): callable
368+ public function getName(): Closure
355369 {
356370 return fn() => $this->name;
357371 }
0 commit comments