public boolean isSubTypeOf()

in src/main/com/intellij/lang/jsgraphql/types/schema/idl/TypeDefinitionRegistry.java [540:583]


  public boolean isSubTypeOf(Type maybeSubType, Type superType) {
    TypeInfo maybeSubTypeInfo = TypeInfo.typeInfo(maybeSubType);
    TypeInfo superTypeInfo = TypeInfo.typeInfo(superType);
    // Equivalent type is a valid subtype
    if (maybeSubTypeInfo.equals(superTypeInfo)) {
      return true;
    }


    // If superType is non-null, maybeSubType must also be non-null.
    if (superTypeInfo.isNonNull()) {
      if (maybeSubTypeInfo.isNonNull()) {
        return isSubTypeOf(maybeSubTypeInfo.unwrapOneType(), superTypeInfo.unwrapOneType());
      }
      return false;
    }
    if (maybeSubTypeInfo.isNonNull()) {
      // If superType is nullable, maybeSubType may be non-null or nullable.
      return isSubTypeOf(maybeSubTypeInfo.unwrapOneType(), superType);
    }

    // If superType type is a list, maybeSubType type must also be a list.
    if (superTypeInfo.isList()) {
      if (maybeSubTypeInfo.isList()) {
        return isSubTypeOf(maybeSubTypeInfo.unwrapOneType(), superTypeInfo.unwrapOneType());
      }
      return false;
    }
    if (maybeSubTypeInfo.isList()) {
      // If superType is not a list, maybeSubType must also be not a list.
      return false;
    }

    // If superType type is an abstract type, maybeSubType type may be a currently
    // possible object type.
    if (isInterfaceOrUnion(superType) &&
        isObjectTypeOrInterface(maybeSubType) &&
        isPossibleType(superType, maybeSubType)) {
      return true;
    }

    // Otherwise, the child type is not a valid subtype of the parent type.
    return false;
  }