mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
More consistent naming
This commit is contained in:
parent
8da3043702
commit
24f236403a
@ -54,8 +54,8 @@ $queryType = new ObjectType([
|
|||||||
'args' => [
|
'args' => [
|
||||||
'message' => Type::nonNull(Type::string()),
|
'message' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => function ($rootValue, $args) {
|
||||||
return $root['prefix'] . $args['message'];
|
return $rootValue['prefix'] . $args['message'];
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -998,7 +998,7 @@ visitor API:
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
static function visit($root, $visitor, $keyMap = null)
|
static function visit($rootValue, $visitor, $keyMap = null)
|
||||||
```
|
```
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
@ -158,7 +158,7 @@ $heroType = new ObjectType([
|
|||||||
'args' => [
|
'args' => [
|
||||||
'episode' => Type::nonNull($enumType)
|
'episode' => Type::nonNull($enumType)
|
||||||
],
|
],
|
||||||
'resolve' => function($root, $args) {
|
'resolve' => function($rootValue, $args) {
|
||||||
return $args['episode'] === 5 ? true : false;
|
return $args['episode'] === 5 ? true : false;
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -19,8 +19,8 @@ try {
|
|||||||
'args' => [
|
'args' => [
|
||||||
'message' => ['type' => Type::string()],
|
'message' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => function ($rootValue, $args) {
|
||||||
return $root['prefix'] . $args['message'];
|
return $rootValue['prefix'] . $args['message'];
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@ -35,7 +35,7 @@ try {
|
|||||||
'x' => ['type' => Type::int()],
|
'x' => ['type' => Type::int()],
|
||||||
'y' => ['type' => Type::int()],
|
'y' => ['type' => Type::int()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => function ($rootValue, $args) {
|
||||||
return $args['x'] + $args['y'];
|
return $args['x'] + $args['y'];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
interface Resolver {
|
interface Resolver {
|
||||||
public function resolve($root, $args, $context);
|
public function resolve($rootValue, $args, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Addition implements Resolver
|
class Addition implements Resolver
|
||||||
{
|
{
|
||||||
public function resolve($root, $args, $context)
|
public function resolve($rootValue, $args, $context)
|
||||||
{
|
{
|
||||||
return $args['x'] + $args['y'];
|
return $args['x'] + $args['y'];
|
||||||
}
|
}
|
||||||
@ -14,22 +14,22 @@ class Addition implements Resolver
|
|||||||
|
|
||||||
class Echoer implements Resolver
|
class Echoer implements Resolver
|
||||||
{
|
{
|
||||||
public function resolve($root, $args, $context)
|
public function resolve($rootValue, $args, $context)
|
||||||
{
|
{
|
||||||
return $root['prefix'].$args['message'];
|
return $rootValue['prefix'].$args['message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'sum' => function($root, $args, $context) {
|
'sum' => function($rootValue, $args, $context) {
|
||||||
$sum = new Addition();
|
$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();
|
$echo = new Echoer();
|
||||||
|
|
||||||
return $echo->resolve($root, $args, $context);
|
return $echo->resolve($rootValue, $args, $context);
|
||||||
},
|
},
|
||||||
'prefix' => 'You said: ',
|
'prefix' => 'You said: ',
|
||||||
];
|
];
|
||||||
|
@ -19,8 +19,8 @@ try {
|
|||||||
'args' => [
|
'args' => [
|
||||||
'message' => ['type' => Type::string()],
|
'message' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => function ($rootValue, $args) {
|
||||||
return $root['prefix'] . $args['message'];
|
return $rootValue['prefix'] . $args['message'];
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@ -35,7 +35,7 @@ try {
|
|||||||
'x' => ['type' => Type::int()],
|
'x' => ['type' => Type::int()],
|
||||||
'y' => ['type' => Type::int()],
|
'y' => ['type' => Type::int()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => function ($rootValue, $args) {
|
||||||
return $args['x'] + $args['y'];
|
return $args['x'] + $args['y'];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -385,13 +385,13 @@ class Helper
|
|||||||
*/
|
*/
|
||||||
private function resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, $operationType)
|
private function resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, $operationType)
|
||||||
{
|
{
|
||||||
$root = $config->getRootValue();
|
$rootValue = $config->getRootValue();
|
||||||
|
|
||||||
if (is_callable($root)) {
|
if (is_callable($rootValue)) {
|
||||||
$root = $root($params, $doc, $operationType);
|
$rootValue = $rootValue($params, $doc, $operationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $root;
|
return $rootValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
'article' => [
|
'article' => [
|
||||||
'type' => $BlogArticle,
|
'type' => $BlogArticle,
|
||||||
'args' => ['id' => ['type' => Type::id()]],
|
'args' => ['id' => ['type' => Type::id()]],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => function ($rootValue, $args) {
|
||||||
return $this->article($args['id']);
|
return $this->article($args['id']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -273,7 +273,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'test' => [
|
'test' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => static function ($root, $args, $ctx, $_info) use (&$info) {
|
'resolve' => static function ($rootValue, $args, $ctx, $_info) use (&$info) {
|
||||||
$info = $_info;
|
$info = $_info;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -16,7 +16,7 @@ class Adder
|
|||||||
{
|
{
|
||||||
$this->num = $num;
|
$this->num = $num;
|
||||||
|
|
||||||
$this->test = function ($root, $args, $context) {
|
$this->test = function ($rootValue, $args, $context) {
|
||||||
return $this->num + $args['addend1'] + $context['addend2'];
|
return $this->num + $args['addend1'] + $context['addend2'];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class GraphQLTest extends TestCase
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'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']));
|
return $promiseAdapter->createFulfilled(sprintf('Hi %s!', $args['name']));
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -30,7 +30,7 @@ class Issue396Test extends TestCase
|
|||||||
$unionResult = new UnionType([
|
$unionResult = new UnionType([
|
||||||
'name' => 'UnionResult',
|
'name' => 'UnionResult',
|
||||||
'types' => [$a, $b, $c],
|
'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];
|
$log[] = [$result, $info->path];
|
||||||
if (stristr($result['name'], 'A')) {
|
if (stristr($result['name'], 'A')) {
|
||||||
return $a;
|
return $a;
|
||||||
@ -97,7 +97,7 @@ class Issue396Test extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => Type::string(),
|
'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];
|
$log[] = [$result, $info->path];
|
||||||
if (stristr($result['name'], 'A')) {
|
if (stristr($result['name'], 'A')) {
|
||||||
return $a;
|
return $a;
|
||||||
|
@ -25,13 +25,13 @@ abstract class ServerTestCase extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'f1' => [
|
'f1' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => static function ($root, $args, $context, $info) {
|
'resolve' => static function ($rootValue, $args, $context, $info) {
|
||||||
return $info->fieldName;
|
return $info->fieldName;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'fieldWithPhpError' => [
|
'fieldWithPhpError' => [
|
||||||
'type' => Type::string(),
|
'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('deprecated', E_USER_DEPRECATED);
|
||||||
trigger_error('notice', E_USER_NOTICE);
|
trigger_error('notice', E_USER_NOTICE);
|
||||||
trigger_error('warning', E_USER_WARNING);
|
trigger_error('warning', E_USER_WARNING);
|
||||||
@ -55,8 +55,8 @@ abstract class ServerTestCase extends TestCase
|
|||||||
],
|
],
|
||||||
'testContextAndRootValue' => [
|
'testContextAndRootValue' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => static function ($root, $args, $context, $info) {
|
'resolve' => static function ($rootValue, $args, $context, $info) {
|
||||||
$context->testedRootValue = $root;
|
$context->testedRootValue = $rootValue;
|
||||||
|
|
||||||
return $info->fieldName;
|
return $info->fieldName;
|
||||||
},
|
},
|
||||||
@ -68,7 +68,7 @@ abstract class ServerTestCase extends TestCase
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'type' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
return $args['arg'];
|
return $args['arg'];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -79,7 +79,7 @@ abstract class ServerTestCase extends TestCase
|
|||||||
'type' => Type::nonNull(Type::int()),
|
'type' => Type::nonNull(Type::int()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args, $context) {
|
'resolve' => static function ($rootValue, $args, $context) {
|
||||||
$context['buffer']($args['num']);
|
$context['buffer']($args['num']);
|
||||||
|
|
||||||
return new Deferred(static function () use ($args, $context) {
|
return new Deferred(static function () use ($args, $context) {
|
||||||
|
@ -273,7 +273,7 @@ class StarWarsSchema
|
|||||||
'type' => $episodeEnum,
|
'type' => $episodeEnum,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
return StarWarsData::getHero($args['episode'] ?? null);
|
return StarWarsData::getHero($args['episode'] ?? null);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -286,7 +286,7 @@ class StarWarsSchema
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'type' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
$humans = StarWarsData::humans();
|
$humans = StarWarsData::humans();
|
||||||
|
|
||||||
return $humans[$args['id']] ?? null;
|
return $humans[$args['id']] ?? null;
|
||||||
@ -301,7 +301,7 @@ class StarWarsSchema
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'type' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
$droids = StarWarsData::droids();
|
$droids = StarWarsData::droids();
|
||||||
|
|
||||||
return $droids[$args['id']] ?? null;
|
return $droids[$args['id']] ?? null;
|
||||||
|
@ -74,7 +74,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'fromInt' => ['type' => Type::int()],
|
'fromInt' => ['type' => Type::int()],
|
||||||
'fromString' => ['type' => Type::string()],
|
'fromString' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
if (isset($args['fromInt'])) {
|
if (isset($args['fromInt'])) {
|
||||||
return $args['fromInt'];
|
return $args['fromInt'];
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'fromName' => ['type' => Type::string()],
|
'fromName' => ['type' => Type::string()],
|
||||||
'fromValue' => ['type' => Type::string()],
|
'fromValue' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
if (isset($args['fromName'])) {
|
if (isset($args['fromName'])) {
|
||||||
return $args['fromName'];
|
return $args['fromName'];
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'fromEnum' => ['type' => $ColorType],
|
'fromEnum' => ['type' => $ColorType],
|
||||||
'fromInt' => ['type' => Type::int()],
|
'fromInt' => ['type' => Type::int()],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
if (isset($args['fromInt'])) {
|
if (isset($args['fromInt'])) {
|
||||||
return $args['fromInt'];
|
return $args['fromInt'];
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'type' => Type::boolean(),
|
'type' => Type::boolean(),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => static function ($root, $args) use ($Complex2) {
|
'resolve' => static function ($rootValue, $args) use ($Complex2) {
|
||||||
if (! empty($args['provideGoodValue'])) {
|
if (! empty($args['provideGoodValue'])) {
|
||||||
// Note: this is one of the references of the internal values which
|
// Note: this is one of the references of the internal values which
|
||||||
// ComplexEnum allows.
|
// ComplexEnum allows.
|
||||||
@ -156,7 +156,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'favoriteEnum' => [
|
'favoriteEnum' => [
|
||||||
'type' => $ColorType,
|
'type' => $ColorType,
|
||||||
'args' => ['color' => ['type' => $ColorType]],
|
'args' => ['color' => ['type' => $ColorType]],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
return $args['color'] ?? null;
|
return $args['color'] ?? null;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -169,7 +169,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'subscribeToEnum' => [
|
'subscribeToEnum' => [
|
||||||
'type' => $ColorType,
|
'type' => $ColorType,
|
||||||
'args' => ['color' => ['type' => $ColorType]],
|
'args' => ['color' => ['type' => $ColorType]],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
return $args['color'] ?? null;
|
return $args['color'] ?? null;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1049,7 +1049,7 @@ class IntrospectionTest extends TestCase
|
|||||||
'field' => [
|
'field' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'args' => ['complex' => ['type' => $TestInputObject]],
|
'args' => ['complex' => ['type' => $TestInputObject]],
|
||||||
'resolve' => static function ($root, $args) {
|
'resolve' => static function ($rootValue, $args) {
|
||||||
return json_encode($args['complex']);
|
return json_encode($args['complex']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -51,7 +51,7 @@ class BuildSchemaTest extends TestCase
|
|||||||
');
|
');
|
||||||
|
|
||||||
$root = [
|
$root = [
|
||||||
'add' => static function ($root, $args) {
|
'add' => static function ($rootValue, $args) {
|
||||||
return $args['x'] + $args['y'];
|
return $args['x'] + $args['y'];
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -464,7 +464,7 @@ type WorldTwo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
';
|
';
|
||||||
$root = [
|
$rootValue = [
|
||||||
'fruits' => [
|
'fruits' => [
|
||||||
[
|
[
|
||||||
'color' => 'green',
|
'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));
|
self::assertEquals($expected, $result->toArray(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,7 +526,7 @@ type WorldTwo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
';
|
';
|
||||||
$root = [
|
$rootValue = [
|
||||||
'characters' => [
|
'characters' => [
|
||||||
[
|
[
|
||||||
'name' => 'Han Solo',
|
'name' => 'Han Solo',
|
||||||
@ -549,7 +549,7 @@ type WorldTwo {
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = GraphQL::executeQuery($schema, $query, $root);
|
$result = GraphQL::executeQuery($schema, $query, $rootValue);
|
||||||
self::assertEquals($expected, $result->toArray(true));
|
self::assertEquals($expected, $result->toArray(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user