doTypesConflict function

bool doTypesConflict(
  1. GraphQLType type1,
  2. GraphQLType type2
)

Two types conflict if both types could not apply to a value simultaneously. Composite types are ignored as their individual field types will be compared later recursively. However List and Non-Null types must match.

Implementation

bool doTypesConflict(
  GraphQLType type1,
  GraphQLType type2,
) {
  if (type1 is GraphQLListType) {
    return type2 is! GraphQLListType ||
        doTypesConflict(type1.ofType, type2.ofType);
  }
  if (type2 is GraphQLListType) {
    return true;
  }
  if (type1 is GraphQLNonNullType) {
    return type2 is! GraphQLNonNullType ||
        doTypesConflict(type1.ofType, type2.ofType);
  }
  if (type2 is GraphQLNonNullType) {
    return true;
  }
  if (isLeafType(type1) || isLeafType(type2)) {
    return type1 != type2;
  }
  return false;
}