Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules
VariablesInAllowedPosition::allowedVariableUsage
Returns true if the variable is allowed in the location it was found, which includes considering if default values exist for either the variable or the location at which it is located.
Method of the class: VariablesInAllowedPosition{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->allowedVariableUsage( $schema, $varType, $varDefaultValue, $locationType, $locationDefaultValue ): bool;
- $schema(Schema) (required)
- .
- $varType(Type) (required)
- .
- $varDefaultValue(ValueNode|null) (required)
- .
- $locationType(Type) (required)
- .
- $locationDefaultValue(mixed) (required)
- .
VariablesInAllowedPosition::allowedVariableUsage() VariablesInAllowedPosition::allowedVariableUsage code WC 10.9.1
protected function allowedVariableUsage(Schema $schema, Type $varType, $varDefaultValue, Type $locationType, $locationDefaultValue): bool
{
if ($locationType instanceof NonNull && ! $varType instanceof NonNull) {
$hasNonNullVariableDefaultValue = $varDefaultValue !== null && ! $varDefaultValue instanceof NullValueNode;
$hasLocationDefaultValue = Utils::undefined() !== $locationDefaultValue;
if (! $hasNonNullVariableDefaultValue && ! $hasLocationDefaultValue) {
return false;
}
$nullableLocationType = $locationType->getWrappedType();
return TypeComparators::isTypeSubTypeOf($schema, $varType, $nullableLocationType);
}
return TypeComparators::isTypeSubTypeOf($schema, $varType, $locationType);
}