Automattic\WooCommerce\Vendor\GraphQL\Executor
ReferenceExecutor::resolveField
Resolves the field on the given root value.
In particular, this figures out the value that the field returns by calling its resolve function, then calls completeValue to complete promises, serialize scalars, or execute the sub-selection-set for objects.
Method of the class: ReferenceExecutor{}
No Hooks.
Returns
Array
Usage
// protected - for code of main (parent) or child class $result = $this->resolveField( $parentType, $rootValue, $fieldNodes, $responseName, $path, $unaliasedPath, $contextValue );
- $parentType(ObjectType) (required)
- .
- $rootValue(mixed) (required)
- .
- $fieldNodes(ArrayObject) (required)
- .
- $responseName(string) (required)
- .
- $path(list<string|int>) (required)
- .
- $unaliasedPath(list<string|int>) (required)
- .
- $contextValue(mixed) (required)
- .
ReferenceExecutor::resolveField() ReferenceExecutor::resolveField code WC 10.9.1
protected function resolveField(
ObjectType $parentType,
$rootValue,
\ArrayObject $fieldNodes,
string $responseName,
array $path,
array $unaliasedPath,
$contextValue
) {
$exeContext = $this->exeContext;
$fieldNode = $fieldNodes[0];
assert($fieldNode instanceof FieldNode, '$fieldNodes is non-empty');
$fieldName = $fieldNode->name->value;
$fieldDef = $this->getFieldDef($exeContext->schema, $parentType, $fieldName);
if ($fieldDef === null || ! $fieldDef->isVisible()) {
return static::$UNDEFINED;
}
$path[] = $responseName;
$unaliasedPath[] = $fieldName;
$returnType = $fieldDef->getType();
// The resolve function's optional 3rd argument is a context value that
// is provided to every resolve function within an execution. It is commonly
// used to represent an authenticated user, or request-specific caches.
// The resolve function's optional 4th argument is a collection of
// information about the current execution state.
$info = new ResolveInfo(
$fieldDef,
$fieldNodes,
$parentType,
$path,
$exeContext->schema,
$exeContext->fragments,
$exeContext->rootValue,
$exeContext->operation,
$exeContext->variableValues,
$unaliasedPath
);
$resolveFn = $fieldDef->resolveFn
?? $parentType->resolveFieldFn
?? $this->exeContext->fieldResolver;
$argsMapper = $fieldDef->argsMapper
?? $parentType->argsMapper
?? $this->exeContext->argsMapper;
// Get the resolve function, regardless of if its result is normal
// or abrupt (error).
$result = $this->resolveFieldValueOrError(
$fieldDef,
$fieldNode,
$resolveFn,
$argsMapper,
$rootValue,
$info,
$contextValue
);
return $this->completeValueCatchingError(
$returnType,
$fieldNodes,
$info,
$path,
$unaliasedPath,
$result,
$contextValue
);
}