diff --git a/docs/getting-started.md b/docs/getting-started.md index 4477cda..69abf8e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -54,8 +54,8 @@ $queryType = new ObjectType([ 'args' => [ 'message' => Type::nonNull(Type::string()), ], - 'resolve' => function ($root, $args) { - return $root['prefix'] . $args['message']; + 'resolve' => function ($rootValue, $args) { + return $rootValue['prefix'] . $args['message']; } ], ], diff --git a/docs/reference.md b/docs/reference.md index c9f4a11..b579179 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -998,7 +998,7 @@ visitor API: * * @api */ -static function visit($root, $visitor, $keyMap = null) +static function visit($rootValue, $visitor, $keyMap = null) ``` ```php diff --git a/docs/type-system/enum-types.md b/docs/type-system/enum-types.md index 6170c0c..ea62c2b 100644 --- a/docs/type-system/enum-types.md +++ b/docs/type-system/enum-types.md @@ -158,7 +158,7 @@ $heroType = new ObjectType([ 'args' => [ 'episode' => Type::nonNull($enumType) ], - 'resolve' => function($root, $args) { + 'resolve' => function($rootValue, $args) { return $args['episode'] === 5 ? true : false; } ] diff --git a/examples/00-hello-world/graphql.php b/examples/00-hello-world/graphql.php index 30b1f9c..167b44d 100644 --- a/examples/00-hello-world/graphql.php +++ b/examples/00-hello-world/graphql.php @@ -19,8 +19,8 @@ try { 'args' => [ 'message' => ['type' => Type::string()], ], - 'resolve' => function ($root, $args) { - return $root['prefix'] . $args['message']; + 'resolve' => function ($rootValue, $args) { + return $rootValue['prefix'] . $args['message']; } ], ], @@ -35,7 +35,7 @@ try { 'x' => ['type' => Type::int()], 'y' => ['type' => Type::int()], ], - 'resolve' => function ($root, $args) { + 'resolve' => function ($rootValue, $args) { return $args['x'] + $args['y']; }, ], diff --git a/examples/02-shorthand/rootvalue.php b/examples/02-shorthand/rootvalue.php index 97e0a82..c16d62b 100644 --- a/examples/02-shorthand/rootvalue.php +++ b/examples/02-shorthand/rootvalue.php @@ -1,12 +1,12 @@ function($root, $args, $context) { + 'sum' => function($rootValue, $args, $context) { $sum = new Addition(); - return $sum->resolve($root, $args, $context); + return $sum->resolve($rootValue, $args, $context); }, - 'echo' => function($root, $args, $context) { + 'echo' => function($rootValue, $args, $context) { $echo = new Echoer(); - return $echo->resolve($root, $args, $context); + return $echo->resolve($rootValue, $args, $context); }, 'prefix' => 'You said: ', ]; diff --git a/examples/03-server/graphql.php b/examples/03-server/graphql.php index 0c01195..8b73f44 100644 --- a/examples/03-server/graphql.php +++ b/examples/03-server/graphql.php @@ -19,8 +19,8 @@ try { 'args' => [ 'message' => ['type' => Type::string()], ], - 'resolve' => function ($root, $args) { - return $root['prefix'] . $args['message']; + 'resolve' => function ($rootValue, $args) { + return $rootValue['prefix'] . $args['message']; } ], ], @@ -35,7 +35,7 @@ try { 'x' => ['type' => Type::int()], 'y' => ['type' => Type::int()], ], - 'resolve' => function ($root, $args) { + 'resolve' => function ($rootValue, $args) { return $args['x'] + $args['y']; }, ], diff --git a/src/Server/Helper.php b/src/Server/Helper.php index ff62b2b..9c522c0 100644 --- a/src/Server/Helper.php +++ b/src/Server/Helper.php @@ -385,13 +385,13 @@ class Helper */ private function resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, $operationType) { - $root = $config->getRootValue(); + $rootValue = $config->getRootValue(); - if (is_callable($root)) { - $root = $root($params, $doc, $operationType); + if (is_callable($rootValue)) { + $rootValue = $rootValue($params, $doc, $operationType); } - return $root; + return $rootValue; } /** diff --git a/tests/Executor/ExecutorSchemaTest.php b/tests/Executor/ExecutorSchemaTest.php index 2a0fd99..ae5a3c1 100644 --- a/tests/Executor/ExecutorSchemaTest.php +++ b/tests/Executor/ExecutorSchemaTest.php @@ -75,7 +75,7 @@ class ExecutorSchemaTest extends TestCase 'article' => [ 'type' => $BlogArticle, 'args' => ['id' => ['type' => Type::id()]], - 'resolve' => function ($root, $args) { + 'resolve' => function ($rootValue, $args) { return $this->article($args['id']); }, ], diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index 7e7082b..76b4beb 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -273,7 +273,7 @@ class ExecutorTest extends TestCase 'fields' => [ 'test' => [ 'type' => Type::string(), - 'resolve' => static function ($root, $args, $ctx, $_info) use (&$info) { + 'resolve' => static function ($rootValue, $args, $ctx, $_info) use (&$info) { $info = $_info; }, ], diff --git a/tests/Executor/TestClasses/Adder.php b/tests/Executor/TestClasses/Adder.php index 804617b..416cd5e 100644 --- a/tests/Executor/TestClasses/Adder.php +++ b/tests/Executor/TestClasses/Adder.php @@ -16,7 +16,7 @@ class Adder { $this->num = $num; - $this->test = function ($root, $args, $context) { + $this->test = function ($rootValue, $args, $context) { return $this->num + $args['addend1'] + $context['addend2']; }; } diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php index 15da589..6d28e09 100644 --- a/tests/GraphQLTest.php +++ b/tests/GraphQLTest.php @@ -30,7 +30,7 @@ class GraphQLTest extends TestCase 'type' => Type::nonNull(Type::string()), ], ], - 'resolve' => static function ($root, $args) use ($promiseAdapter) { + 'resolve' => static function ($rootValue, $args) use ($promiseAdapter) { return $promiseAdapter->createFulfilled(sprintf('Hi %s!', $args['name'])); }, ], diff --git a/tests/Regression/Issue396Test.php b/tests/Regression/Issue396Test.php index 41d0b79..f7c26a9 100644 --- a/tests/Regression/Issue396Test.php +++ b/tests/Regression/Issue396Test.php @@ -30,7 +30,7 @@ class Issue396Test extends TestCase $unionResult = new UnionType([ 'name' => 'UnionResult', 'types' => [$a, $b, $c], - 'resolveType' => static function ($result, $root, ResolveInfo $info) use ($a, $b, $c, &$log) : Type { + 'resolveType' => static function ($result, $rootValue, ResolveInfo $info) use ($a, $b, $c, &$log) : Type { $log[] = [$result, $info->path]; if (stristr($result['name'], 'A')) { return $a; @@ -97,7 +97,7 @@ class Issue396Test extends TestCase 'fields' => [ 'name' => Type::string(), ], - 'resolveType' => static function ($result, $root, ResolveInfo $info) use (&$a, &$b, &$c, &$log) : Type { + 'resolveType' => static function ($result, $rootValue, ResolveInfo $info) use (&$a, &$b, &$c, &$log) : Type { $log[] = [$result, $info->path]; if (stristr($result['name'], 'A')) { return $a; diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 072acba..d94ac34 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -25,13 +25,13 @@ abstract class ServerTestCase extends TestCase 'fields' => [ 'f1' => [ 'type' => Type::string(), - 'resolve' => static function ($root, $args, $context, $info) { + 'resolve' => static function ($rootValue, $args, $context, $info) { return $info->fieldName; }, ], 'fieldWithPhpError' => [ 'type' => Type::string(), - 'resolve' => static function ($root, $args, $context, $info) { + 'resolve' => static function ($rootValue, $args, $context, $info) { trigger_error('deprecated', E_USER_DEPRECATED); trigger_error('notice', E_USER_NOTICE); trigger_error('warning', E_USER_WARNING); @@ -55,8 +55,8 @@ abstract class ServerTestCase extends TestCase ], 'testContextAndRootValue' => [ 'type' => Type::string(), - 'resolve' => static function ($root, $args, $context, $info) { - $context->testedRootValue = $root; + 'resolve' => static function ($rootValue, $args, $context, $info) { + $context->testedRootValue = $rootValue; return $info->fieldName; }, @@ -68,7 +68,7 @@ abstract class ServerTestCase extends TestCase 'type' => Type::nonNull(Type::string()), ], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { return $args['arg']; }, ], @@ -79,7 +79,7 @@ abstract class ServerTestCase extends TestCase 'type' => Type::nonNull(Type::int()), ], ], - 'resolve' => static function ($root, $args, $context) { + 'resolve' => static function ($rootValue, $args, $context) { $context['buffer']($args['num']); return new Deferred(static function () use ($args, $context) { diff --git a/tests/StarWarsSchema.php b/tests/StarWarsSchema.php index b9240af..86221e6 100644 --- a/tests/StarWarsSchema.php +++ b/tests/StarWarsSchema.php @@ -273,7 +273,7 @@ class StarWarsSchema 'type' => $episodeEnum, ], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { return StarWarsData::getHero($args['episode'] ?? null); }, ], @@ -286,7 +286,7 @@ class StarWarsSchema 'type' => Type::nonNull(Type::string()), ], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { $humans = StarWarsData::humans(); return $humans[$args['id']] ?? null; @@ -301,7 +301,7 @@ class StarWarsSchema 'type' => Type::nonNull(Type::string()), ], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { $droids = StarWarsData::droids(); return $droids[$args['id']] ?? null; diff --git a/tests/Type/EnumTypeTest.php b/tests/Type/EnumTypeTest.php index 8e579de..b1649be 100644 --- a/tests/Type/EnumTypeTest.php +++ b/tests/Type/EnumTypeTest.php @@ -74,7 +74,7 @@ class EnumTypeTest extends TestCase 'fromInt' => ['type' => Type::int()], 'fromString' => ['type' => Type::string()], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { if (isset($args['fromInt'])) { return $args['fromInt']; } @@ -92,7 +92,7 @@ class EnumTypeTest extends TestCase 'fromName' => ['type' => Type::string()], 'fromValue' => ['type' => Type::string()], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { if (isset($args['fromName'])) { return $args['fromName']; } @@ -107,7 +107,7 @@ class EnumTypeTest extends TestCase 'fromEnum' => ['type' => $ColorType], 'fromInt' => ['type' => Type::int()], ], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { if (isset($args['fromInt'])) { return $args['fromInt']; } @@ -132,7 +132,7 @@ class EnumTypeTest extends TestCase 'type' => Type::boolean(), ], ], - 'resolve' => static function ($root, $args) use ($Complex2) { + 'resolve' => static function ($rootValue, $args) use ($Complex2) { if (! empty($args['provideGoodValue'])) { // Note: this is one of the references of the internal values which // ComplexEnum allows. @@ -156,7 +156,7 @@ class EnumTypeTest extends TestCase 'favoriteEnum' => [ 'type' => $ColorType, 'args' => ['color' => ['type' => $ColorType]], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { return $args['color'] ?? null; }, ], @@ -169,7 +169,7 @@ class EnumTypeTest extends TestCase 'subscribeToEnum' => [ 'type' => $ColorType, 'args' => ['color' => ['type' => $ColorType]], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { return $args['color'] ?? null; }, ], diff --git a/tests/Type/IntrospectionTest.php b/tests/Type/IntrospectionTest.php index d92bba0..afea3d9 100644 --- a/tests/Type/IntrospectionTest.php +++ b/tests/Type/IntrospectionTest.php @@ -1049,7 +1049,7 @@ class IntrospectionTest extends TestCase 'field' => [ 'type' => Type::string(), 'args' => ['complex' => ['type' => $TestInputObject]], - 'resolve' => static function ($root, $args) { + 'resolve' => static function ($rootValue, $args) { return json_encode($args['complex']); }, ], diff --git a/tests/Utils/BuildSchemaTest.php b/tests/Utils/BuildSchemaTest.php index e8e3280..0ca56c9 100644 --- a/tests/Utils/BuildSchemaTest.php +++ b/tests/Utils/BuildSchemaTest.php @@ -51,7 +51,7 @@ class BuildSchemaTest extends TestCase '); $root = [ - 'add' => static function ($root, $args) { + 'add' => static function ($rootValue, $args) { return $args['x'] + $args['y']; }, ]; @@ -437,7 +437,7 @@ type WorldTwo { */ public function testSpecifyingUnionTypeUsingTypename() : void { - $schema = BuildSchema::buildAST(Parser::parse(' + $schema = BuildSchema::buildAST(Parser::parse(' type Query { fruits: [Fruit] } @@ -452,7 +452,7 @@ type WorldTwo { length: Int } ')); - $query = ' + $query = ' { fruits { ... on Apple { @@ -464,7 +464,7 @@ type WorldTwo { } } '; - $root = [ + $rootValue = [ 'fruits' => [ [ 'color' => 'green', @@ -476,7 +476,7 @@ type WorldTwo { ], ], ]; - $expected = [ + $expected = [ 'data' => [ 'fruits' => [ ['color' => 'green'], @@ -485,7 +485,7 @@ type WorldTwo { ], ]; - $result = GraphQL::executeQuery($schema, $query, $root); + $result = GraphQL::executeQuery($schema, $query, $rootValue); self::assertEquals($expected, $result->toArray(true)); } @@ -494,7 +494,7 @@ type WorldTwo { */ public function testSpecifyingInterfaceUsingTypename() : void { - $schema = BuildSchema::buildAST(Parser::parse(' + $schema = BuildSchema::buildAST(Parser::parse(' type Query { characters: [Character] } @@ -513,7 +513,7 @@ type WorldTwo { primaryFunction: String } ')); - $query = ' + $query = ' { characters { name @@ -526,7 +526,7 @@ type WorldTwo { } } '; - $root = [ + $rootValue = [ 'characters' => [ [ 'name' => 'Han Solo', @@ -540,7 +540,7 @@ type WorldTwo { ], ], ]; - $expected = [ + $expected = [ 'data' => [ 'characters' => [ ['name' => 'Han Solo', 'totalCredits' => 10], @@ -549,7 +549,7 @@ type WorldTwo { ], ]; - $result = GraphQL::executeQuery($schema, $query, $root); + $result = GraphQL::executeQuery($schema, $query, $rootValue); self::assertEquals($expected, $result->toArray(true)); }