collectConflictsWithin function

void collectConflictsWithin(
  1. ValidationCtx context,
  2. List<Conflict> conflicts,
  3. Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  4. PairSet comparedFragmentPairs,
  5. NodeAndDefCollection fieldMap,
)

Collect all Conflicts "within" one collection of fields.

Implementation

void collectConflictsWithin(
  ValidationCtx context,
  List<Conflict> conflicts,
  Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  PairSet comparedFragmentPairs,
  NodeAndDefCollection fieldMap,
) {
  // A field map is a keyed collection, where each key represents a response
  // name and the value at that key is a list of all fields which provide that
  // response name. For every response name, if there are multiple fields, they
  // must be compared to find a potential conflict.
  for (final e in fieldMap.entries) {
    final responseName = e.key;
    final fields = e.value;
    // This compares every field in the list to every other field in this list
    // (except to itself). If the list only has one item, nothing needs to
    // be compared.
    if (fields.length > 1) {
      for (int i = 0; i < fields.length; i++) {
        for (int j = i + 1; j < fields.length; j++) {
          final conflict = findConflict(
            context,
            cachedFieldsAndFragmentNames,
            comparedFragmentPairs,
            false, // within one collection is never mutually exclusive
            responseName,
            fields[i],
            fields[j],
          );
          if (conflict != null) {
            conflicts.add(conflict);
          }
        }
      }
    }
  }
}