From 8c4e7b178d6c744de72c93b47e8a71d97e7fb862 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Mon, 1 Jul 2019 12:17:04 +0200 Subject: [PATCH] Fix up some overly eager renamings in the docs --- docs/data-fetching.md | 33 ++++++++++++++++----------------- docs/reference.md | 4 ++-- src/Executor/Executor.php | 18 +++++++++--------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/docs/data-fetching.md b/docs/data-fetching.md index 349e702..c5152ba 100644 --- a/docs/data-fetching.md +++ b/docs/data-fetching.md @@ -103,25 +103,25 @@ for a field you simply override this default resolver. **graphql-php** provides following default field resolver: ```php fieldName; - $property = null; +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]; - } - } elseif (is_object($rootValue)) { - if (isset($rootValue->{$fieldName})) { - $property = $rootValue->{$fieldName}; + if (is_array($objectValue) || $objectValue instanceof \ArrayAccess) { + if (isset($objectValue[$fieldName])) { + $property = $objectValue[$fieldName]; + } + } elseif (is_object($objectValue)) { + if (isset($objectValue->{$fieldName})) { + $property = $objectValue->{$fieldName}; + } } + + return $property instanceof Closure + ? $property($objectValue, $args, $context, $info) + : $property; } - - return $property instanceof Closure - ? $property($rootValue, $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 diff --git a/docs/reference.md b/docs/reference.md index 36d4d1a..49f2372 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -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 diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 2877f9d..764fa1c 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -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; } }