Automattic\WooCommerce\Vendor\GraphQL\Executor
ReferenceExecutor::ensureValidRuntimeType
Method of the class: ReferenceExecutor{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->ensureValidRuntimeType( $runtimeTypeOrName, $returnType, $info, $result ): ObjectType;
- $runtimeTypeOrName(mixed) (required)
- .
- $returnType(AbstractType&Type) (required)
- .
- $info(ResolveInfo) (required)
- .
- $result(mixed) (required)
- .
ReferenceExecutor::ensureValidRuntimeType() ReferenceExecutor::ensureValidRuntimeType code WC 10.9.1
protected function ensureValidRuntimeType(
$runtimeTypeOrName,
AbstractType $returnType,
ResolveInfo $info,
$result
): ObjectType {
$runtimeType = is_string($runtimeTypeOrName)
? $this->exeContext->schema->getType($runtimeTypeOrName)
: $runtimeTypeOrName;
if (! $runtimeType instanceof ObjectType) {
$safeResult = Utils::printSafe($result);
$notObjectType = Utils::printSafe($runtimeType);
throw new InvariantViolation("Abstract type {$returnType} must resolve to an Object type at runtime for field {$info->parentType}.{$info->fieldName} with value {$safeResult}, received \"{$notObjectType}\". Either the {$returnType} type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.");
}
if (! $this->exeContext->schema->isSubType($returnType, $runtimeType)) {
throw new InvariantViolation("Runtime Object type \"{$runtimeType}\" is not a possible type for \"{$returnType}\".");
}
assert(
$this->exeContext->schema->getType($runtimeType->name) !== null,
"Schema does not contain type \"{$runtimeType}\". This can happen when an object type is only referenced indirectly through abstract types and never directly through fields.List the type in the option \"types\" during schema construction, see https://webonyx.github.io/graphql-php/schema-definition/#configuration-options."
);
assert(
$runtimeType === $this->exeContext->schema->getType($runtimeType->name),
"Schema must contain unique named types but contains multiple types named \"{$runtimeType}\". Make sure that `resolveType` function of abstract type \"{$returnType}\" returns the same type instance as referenced anywhere else within the schema (see https://webonyx.github.io/graphql-php/type-definitions/#type-registry)."
);
return $runtimeType;
}