Fix up some overly eager renamings in the docs

This commit is contained in:
Benedikt Franke 2019-07-01 12:17:04 +02:00
parent 3b33167c87
commit 8c4e7b178d
3 changed files with 27 additions and 28 deletions

View File

@ -103,25 +103,25 @@ for a field you simply override this default resolver.
**graphql-php** provides following default field resolver:
```php
<?php
function defaultFieldResolver($rootValue, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info)
{
function defaultFieldResolver($objectValue, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info)
{
$fieldName = $info->fieldName;
$property = null;
if (is_array($rootValue) || $rootValue instanceof ArrayAccess) {
if (isset($rootValue[$fieldName])) {
$property = $rootValue[$fieldName];
if (is_array($objectValue) || $objectValue instanceof \ArrayAccess) {
if (isset($objectValue[$fieldName])) {
$property = $objectValue[$fieldName];
}
} elseif (is_object($rootValue)) {
if (isset($rootValue->{$fieldName})) {
$property = $rootValue->{$fieldName};
} elseif (is_object($objectValue)) {
if (isset($objectValue->{$fieldName})) {
$property = $objectValue->{$fieldName};
}
}
return $property instanceof Closure
? $property($rootValue, $args, $context, $info)
? $property($objectValue, $args, $context, $info)
: $property;
}
}
```
As you see it returns value by key (for arrays) or property (for objects).
@ -163,7 +163,6 @@ $userType = new ObjectType([
Keep in mind that **field resolver** has precedence over **default field resolver per type** which in turn
has precedence over **default field resolver**.
# Solving N+1 Problem
Since: 0.9.0

View File

@ -33,7 +33,7 @@ See [related documentation](executing-queries.md).
* fieldResolver:
* A resolver function to use when one is not provided by the schema.
* If not provided, the default field resolver is used (which looks for a
* value on the root value with the field's name).
* value on the object value with the field's name).
* validationRules:
* A set of rules for query validation step. Default value is all available rules.
* Empty array would allow to skip query validation (may be convenient for persisted
@ -998,7 +998,7 @@ visitor API:
*
* @api
*/
static function visit($rootValue, $visitor, $keyMap = null)
static function visit($root, $visitor, $keyMap = null)
```
```php

View File

@ -161,29 +161,29 @@ class Executor
* and returns it as the result, or if it's a function, returns the result
* of calling that function while passing along args and context.
*
* @param mixed $rootValue
* @param mixed $objectValue
* @param mixed[] $args
* @param mixed|null $context
*
* @return mixed|null
*/
public static function defaultFieldResolver($rootValue, $args, $context, ResolveInfo $info)
public static function defaultFieldResolver($objectValue, $args, $context, ResolveInfo $info)
{
$fieldName = $info->fieldName;
$property = null;
if (is_array($rootValue) || $rootValue instanceof ArrayAccess) {
if (isset($rootValue[$fieldName])) {
$property = $rootValue[$fieldName];
if (is_array($objectValue) || $objectValue instanceof ArrayAccess) {
if (isset($objectValue[$fieldName])) {
$property = $objectValue[$fieldName];
}
} elseif (is_object($rootValue)) {
if (isset($rootValue->{$fieldName})) {
$property = $rootValue->{$fieldName};
} elseif (is_object($objectValue)) {
if (isset($objectValue->{$fieldName})) {
$property = $objectValue->{$fieldName};
}
}
return $property instanceof Closure
? $property($rootValue, $args, $context, $info)
? $property($objectValue, $args, $context, $info)
: $property;
}
}