getFieldsAndFragmentNames function

FieldsAndFragmentNames getFieldsAndFragmentNames(
  1. ValidationCtx context,
  2. Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  3. GraphQLNamedType? parentType,
  4. SelectionSetNode selectionSet,
)

Given a selection set, return the collection of fields (a mapping of response name to field nodes and definitions) as well as a list of fragment names referenced via fragment spreads.

Implementation

FieldsAndFragmentNames getFieldsAndFragmentNames(
  ValidationCtx context,
  Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  GraphQLNamedType? parentType,
  SelectionSetNode selectionSet,
) {
  final cached = cachedFieldsAndFragmentNames[selectionSet];
  if (cached != null) {
    return cached;
  }
  final NodeAndDefCollection nodeAndDefs = {};
  final fragmentNames = <String, bool>{};
  _collectFieldsAndFragmentNames(
    context,
    parentType,
    selectionSet,
    nodeAndDefs,
    fragmentNames,
  );
  final result =
      FieldsAndFragmentNames(nodeAndDefs, fragmentNames.keys.toList());
  cachedFieldsAndFragmentNames[selectionSet] = result;
  return result;
}