mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-21 20:36:05 +03:00
Rename $rootValue where applicable
This commit is contained in:
parent
d037ab7ec3
commit
3b33167c87
@ -152,7 +152,7 @@ class SchemaGenerator
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveField($rootValue, $args, $context, $resolveInfo)
|
||||
public function resolveField($objectValue, $args, $context, $resolveInfo)
|
||||
{
|
||||
return $resolveInfo->fieldName . '-value';
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ $heroType = new ObjectType([
|
||||
'args' => [
|
||||
'episode' => Type::nonNull($enumType)
|
||||
],
|
||||
'resolve' => function($rootValue, $args) {
|
||||
'resolve' => function($hero, $args) {
|
||||
return $args['episode'] === 5 ? true : false;
|
||||
}
|
||||
]
|
||||
|
@ -69,7 +69,7 @@ name | `string` | **Required.** Unique name of this object type within S
|
||||
fields | `array` or `callable` | **Required**. An array describing object fields or callable returning such an array. See [Fields](#field-definitions) section below for expected structure of each array entry. See also the section on [Circular types](#recurring-and-circular-types) for an explanation of when to use callable for this option.
|
||||
description | `string` | Plain-text description of this type for clients (e.g. used by [GraphiQL](https://github.com/graphql/graphiql) for auto-generated documentation)
|
||||
interfaces | `array` or `callable` | List of interfaces implemented by this type or callable returning such a list. See [Interface Types](interfaces.md) for details. See also the section on [Circular types](#recurring-and-circular-types) for an explanation of when to use callable for this option.
|
||||
isTypeOf | `callable` | **function($rootValue, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Expected to return **true** if **$value** qualifies for this type (see section about [Abstract Type Resolution](interfaces.md#interface-role-in-data-fetching) for explanation).
|
||||
isTypeOf | `callable` | **function($value, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Expected to return **true** if **$value** qualifies for this type (see section about [Abstract Type Resolution](interfaces.md#interface-role-in-data-fetching) for explanation).
|
||||
resolveField | `callable` | **function($value, $args, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Given the **$value** of this type, it is expected to return value for a field defined in **$info->fieldName**. A good place to define a type-specific strategy for field resolution. See section on [Data Fetching](../data-fetching.md) for details.
|
||||
|
||||
# Field configuration options
|
||||
@ -80,7 +80,7 @@ Option | Type | Notes
|
||||
name | `string` | **Required.** Name of the field. When not set - inferred from **fields** array key (read about [shorthand field definition](#shorthand-field-definitions) below)
|
||||
type | `Type` | **Required.** An instance of internal or custom type. Note: type must be represented by a single instance within one schema (see also [Type Registry](index.md#type-registry))
|
||||
args | `array` | An array of possible type arguments. Each entry is expected to be an array with keys: **name**, **type**, **description**, **defaultValue**. See [Field Arguments](#field-arguments) section below.
|
||||
resolve | `callable` | **function($rootValue, $args, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Given the **$value** of this type, it is expected to return actual value of the current field. See section on [Data Fetching](../data-fetching.md) for details
|
||||
resolve | `callable` | **function($objectValue, $args, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Given the **$objectValue** of this type, it is expected to return actual value of the current field. See section on [Data Fetching](../data-fetching.md) for details
|
||||
complexity | `callable` | **function($childrenComplexity, $args)**<br> Used to restrict query complexity. The feature is disabled by default, read about [Security](../security.md#query-complexity-analysis) to use it.
|
||||
description | `string` | Plain-text description of this field for clients (e.g. used by [GraphiQL](https://github.com/graphql/graphiql) for auto-generated documentation)
|
||||
deprecationReason | `string` | Text describing why this field is deprecated. When not empty - field will not be returned by introspection queries (unless forced)
|
||||
|
@ -35,7 +35,7 @@ try {
|
||||
'x' => ['type' => Type::int()],
|
||||
'y' => ['type' => Type::int()],
|
||||
],
|
||||
'resolve' => function ($rootValue, $args) {
|
||||
'resolve' => function ($calc, $args) {
|
||||
return $args['x'] + $args['y'];
|
||||
},
|
||||
],
|
||||
|
@ -35,12 +35,12 @@ class CommentType extends ObjectType
|
||||
Types::htmlField('body')
|
||||
];
|
||||
},
|
||||
'resolveField' => function($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolveField' => function($comment, $args, $context, ResolveInfo $info) {
|
||||
$method = 'resolve' . ucfirst($info->fieldName);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->{$method}($rootValue, $args, $context, $info);
|
||||
return $this->{$method}($comment, $args, $context, $info);
|
||||
} else {
|
||||
return $rootValue->{$info->fieldName};
|
||||
return $comment->{$info->fieldName};
|
||||
}
|
||||
}
|
||||
];
|
||||
|
@ -75,12 +75,12 @@ class StoryType extends ObjectType
|
||||
'interfaces' => [
|
||||
Types::node()
|
||||
],
|
||||
'resolveField' => function($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolveField' => function($story, $args, $context, ResolveInfo $info) {
|
||||
$method = 'resolve' . ucfirst($info->fieldName);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->{$method}($rootValue, $args, $context, $info);
|
||||
return $this->{$method}($story, $args, $context, $info);
|
||||
} else {
|
||||
return $rootValue->{$info->fieldName};
|
||||
return $story->{$info->fieldName};
|
||||
}
|
||||
}
|
||||
];
|
||||
|
@ -44,12 +44,12 @@ class UserType extends ObjectType
|
||||
'interfaces' => [
|
||||
Types::node()
|
||||
],
|
||||
'resolveField' => function($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolveField' => function($user, $args, $context, ResolveInfo $info) {
|
||||
$method = 'resolve' . ucfirst($info->fieldName);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->{$method}($rootValue, $args, $context, $info);
|
||||
return $this->{$method}($user, $args, $context, $info);
|
||||
} else {
|
||||
return $rootValue->{$info->fieldName};
|
||||
return $user->{$info->fieldName};
|
||||
}
|
||||
}
|
||||
];
|
||||
|
@ -35,7 +35,7 @@ try {
|
||||
'x' => ['type' => Type::int()],
|
||||
'y' => ['type' => Type::int()],
|
||||
],
|
||||
'resolve' => function ($rootValue, $args) {
|
||||
'resolve' => function ($calc, $args) {
|
||||
return $args['x'] + $args['y'];
|
||||
},
|
||||
],
|
||||
|
@ -401,7 +401,7 @@ class DeferredFieldsTest extends TestCase
|
||||
return [
|
||||
'sync' => [
|
||||
'type' => Type::string(),
|
||||
'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolve' => function ($complexType, $args, $context, ResolveInfo $info) {
|
||||
$this->paths[] = $info->path;
|
||||
|
||||
return 'sync';
|
||||
@ -409,7 +409,7 @@ class DeferredFieldsTest extends TestCase
|
||||
],
|
||||
'deferred' => [
|
||||
'type' => Type::string(),
|
||||
'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolve' => function ($complexType, $args, $context, ResolveInfo $info) {
|
||||
$this->paths[] = $info->path;
|
||||
|
||||
return new Deferred(function () use ($info) {
|
||||
@ -421,7 +421,7 @@ class DeferredFieldsTest extends TestCase
|
||||
],
|
||||
'nest' => [
|
||||
'type' => $complexType,
|
||||
'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolve' => function ($complexType, $args, $context, ResolveInfo $info) {
|
||||
$this->paths[] = $info->path;
|
||||
|
||||
return [];
|
||||
@ -429,7 +429,7 @@ class DeferredFieldsTest extends TestCase
|
||||
],
|
||||
'deferredNest' => [
|
||||
'type' => $complexType,
|
||||
'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) {
|
||||
'resolve' => function ($complexType, $args, $context, ResolveInfo $info) {
|
||||
$this->paths[] = $info->path;
|
||||
|
||||
return new Deferred(function () use ($info) {
|
||||
|
@ -273,7 +273,7 @@ class ExecutorTest extends TestCase
|
||||
'fields' => [
|
||||
'test' => [
|
||||
'type' => Type::string(),
|
||||
'resolve' => static function ($rootValue, $args, $ctx, $_info) use (&$info) {
|
||||
'resolve' => static function ($test, $args, $ctx, $_info) use (&$info) {
|
||||
$info = $_info;
|
||||
},
|
||||
],
|
||||
|
@ -16,7 +16,7 @@ class Adder
|
||||
{
|
||||
$this->num = $num;
|
||||
|
||||
$this->test = function ($rootValue, $args, $context) {
|
||||
$this->test = function ($objectValue, $args, $context) {
|
||||
return $this->num + $args['addend1'] + $context['addend2'];
|
||||
};
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Issue396Test extends TestCase
|
||||
$unionResult = new UnionType([
|
||||
'name' => 'UnionResult',
|
||||
'types' => [$a, $b, $c],
|
||||
'resolveType' => static function ($result, $rootValue, ResolveInfo $info) use ($a, $b, $c, &$log) : Type {
|
||||
'resolveType' => static function ($result, $value, 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, $rootValue, ResolveInfo $info) use (&$a, &$b, &$c, &$log) : Type {
|
||||
'resolveType' => static function ($result, $value, ResolveInfo $info) use (&$a, &$b, &$c, &$log) : Type {
|
||||
$log[] = [$result, $info->path];
|
||||
if (stristr($result['name'], 'A')) {
|
||||
return $a;
|
||||
|
@ -1049,7 +1049,7 @@ class IntrospectionTest extends TestCase
|
||||
'field' => [
|
||||
'type' => Type::string(),
|
||||
'args' => ['complex' => ['type' => $TestInputObject]],
|
||||
'resolve' => static function ($rootValue, $args) {
|
||||
'resolve' => static function ($testType, $args) {
|
||||
return json_encode($args['complex']);
|
||||
},
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user