Automattic\WooCommerce\Vendor\GraphQL\Utils

BreakingChangesFinder::isChangeSafeForObjectOrInterfaceFieldprivate staticWC 1.0

Method of the class: BreakingChangesFinder{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

BreakingChangesFinder::isChangeSafeForObjectOrInterfaceField() code WC 10.9.1

private static function isChangeSafeForObjectOrInterfaceField(
    Type $oldType,
    Type $newType
): bool {
    if ($oldType instanceof NamedType) {
        return // if they're both named types, see if their names are equivalent
            ($newType instanceof NamedType && $oldType->name === $newType->name)
            // moving from nullable to non-null of the same underlying type is safe
            || ($newType instanceof NonNull
                && self::isChangeSafeForObjectOrInterfaceField($oldType, $newType->getWrappedType()));
    }

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

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

    return false;
}