findConflictsBetweenSubSelectionSets function

List<Conflict> findConflictsBetweenSubSelectionSets(
  1. ValidationCtx context,
  2. Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  3. PairSet comparedFragmentPairs,
  4. bool areMutuallyExclusive,
  5. GraphQLNamedType? parentType1,
  6. SelectionSetNode selectionSet1,
  7. GraphQLNamedType? parentType2,
  8. SelectionSetNode selectionSet2,
)

Find all conflicts found between two selection sets, including those found via spreading in fragments. Called when determining if conflicts exist between the sub-fields of two overlapping fields.

Implementation

List<Conflict> findConflictsBetweenSubSelectionSets(
  ValidationCtx context,
  Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  PairSet comparedFragmentPairs,
  bool areMutuallyExclusive,
  GraphQLNamedType? parentType1,
  SelectionSetNode selectionSet1,
  GraphQLNamedType? parentType2,
  SelectionSetNode selectionSet2,
) {
  final conflicts = <Conflict>[];

  final fg1 = getFieldsAndFragmentNames(
    context,
    cachedFieldsAndFragmentNames,
    parentType1,
    selectionSet1,
  );
  final fieldMap1 = fg1.fieldMap;
  final fragmentNames1 = fg1.fragmentNames;
  final fg2 = getFieldsAndFragmentNames(
    context,
    cachedFieldsAndFragmentNames,
    parentType2,
    selectionSet2,
  );
  final fieldMap2 = fg2.fieldMap;
  final fragmentNames2 = fg2.fragmentNames;

  // (H) First, collect all conflicts between these two collections of field.
  collectConflictsBetween(
    context,
    conflicts,
    cachedFieldsAndFragmentNames,
    comparedFragmentPairs,
    areMutuallyExclusive,
    fieldMap1,
    fieldMap2,
  );

  // (I) Then collect conflicts between the first collection of fields and
  // those referenced by each fragment name associated with the second.
  for (final fragmentName2 in fragmentNames2) {
    collectConflictsBetweenFieldsAndFragment(
      context,
      conflicts,
      cachedFieldsAndFragmentNames,
      comparedFragmentPairs,
      areMutuallyExclusive,
      fieldMap1,
      fragmentName2,
    );
  }

  // (I) Then collect conflicts between the second collection of fields and
  // those referenced by each fragment name associated with the first.
  for (final fragmentName1 in fragmentNames1) {
    collectConflictsBetweenFieldsAndFragment(
      context,
      conflicts,
      cachedFieldsAndFragmentNames,
      comparedFragmentPairs,
      areMutuallyExclusive,
      fieldMap2,
      fragmentName1,
    );
  }

  // (J) Also collect conflicts between any fragment names by the first and
  // fragment names by the second. This compares each item in the first set of
  // names to each item in the second set of names.
  for (final fragmentName1 in fragmentNames1) {
    for (final fragmentName2 in fragmentNames2) {
      collectConflictsBetweenFragments(
        context,
        conflicts,
        cachedFieldsAndFragmentNames,
        comparedFragmentPairs,
        areMutuallyExclusive,
        fragmentName1,
        fragmentName2,
      );
    }
  }
  return conflicts;
}