Automattic\WooCommerce\Vendor\GraphQL\Utils

BreakingChangesFinder::isChangeSafeForInputObjectFieldOrFieldArgprivate staticWC 1.0

Method of the class: BreakingChangesFinder{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = BreakingChangesFinder::isChangeSafeForInputObjectFieldOrFieldArg( $oldType, $newType ): bool;
$oldType(Type) (required)
.
$newType(Type) (required)
.

BreakingChangesFinder::isChangeSafeForInputObjectFieldOrFieldArg() code WC 10.9.1

private static function isChangeSafeForInputObjectFieldOrFieldArg(
    Type $oldType,
    Type $newType
): bool {
    if ($oldType instanceof NamedType) {
        if (! $newType instanceof NamedType) {
            return false;
        }

        // if they're both named types, see if their names are equivalent
        return $oldType->name === $newType->name;
    }

    if ($oldType instanceof ListOfType) {
        // if they're both lists, make sure the underlying types are compatible
        return $newType instanceof ListOfType
            && self::isChangeSafeForInputObjectFieldOrFieldArg(
                $oldType->getWrappedType(),
                $newType->getWrappedType()
            );
    }

    if ($oldType instanceof NonNull) {
        return // if they're both non-null, make sure the underlying types are compatible
            ($newType instanceof NonNull && self::isChangeSafeForInputObjectFieldOrFieldArg(
                $oldType->getWrappedType(),
                $newType->getWrappedType()
            ))
            // moving from non-null to nullable of the same underlying type is safe
            || ! ($newType instanceof NonNull)
            && self::isChangeSafeForInputObjectFieldOrFieldArg($oldType->getWrappedType(), $newType);
    }

    return false;
}