diff --git a/UPGRADE.md b/UPGRADE.md index 976a195..60ccd3b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -39,46 +39,6 @@ GraphQL\Schema::$queryType; So if you rely on any protected properties or methods of any GraphQL class, make sure to delete leading underscores. -### 3. Returning closure from field resolver -Previously when you returned closure from any resolver, expected signature of this closure -was `function($sourceValue)`, new signature is `function($args, $context)` -(now mirrors reference graphql-js implementation) - -Before the change: -```php -new ObjectType([ - 'name' => 'Test', - 'fields' => [ - 'a' => [ - 'type' => Type::string(), - 'resolve' => function() { - return function($value) { - return 'something'; - } - } - ] - ] -]) - -``` -After the change: -```php -new ObjectType([ - 'name' => 'Test', - 'fields' => [ - 'a' => [ - 'type' => Type::string(), - 'resolve' => function() { - return function($args, $context) { - return 'something'; - } - } - ] - ] -]) -``` -(note the closure signature change) - ## Upgrade v0.6.x > v0.7.x There are a few new breaking changes in v0.7.0 that were added to the graphql-js reference implementation diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 14888b3..5418f64 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -675,7 +675,7 @@ class Executor } } - return $property instanceof \Closure ? $property($args, $context) : $property; + return $property instanceof \Closure ? $property($source, $args, $context) : $property; } /** diff --git a/tests/Executor/TestClasses.php b/tests/Executor/TestClasses.php index 89ceae7..a2aac7f 100644 --- a/tests/Executor/TestClasses.php +++ b/tests/Executor/TestClasses.php @@ -107,7 +107,7 @@ class Adder { $this->num = $num; - $this->test = function($args, $context) { + $this->test = function($source, $args, $context) { return $this->num + $args['addend1'] + $context['addend2']; }; }