getReferencedFieldsAndFragmentNames function

FieldsAndFragmentNames getReferencedFieldsAndFragmentNames(
  1. ValidationCtx context,
  2. Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  3. FragmentDefinitionNode fragment
)

Given a reference to a fragment, return the represented collection of fields as well as a list of nested fragment names referenced via fragment spreads.

Implementation

FieldsAndFragmentNames getReferencedFieldsAndFragmentNames(
  ValidationCtx context,
  Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames,
  FragmentDefinitionNode fragment,
) {
  // Short-circuit building a type from the node if possible.
  final cached = cachedFieldsAndFragmentNames[fragment.selectionSet];
  if (cached != null) {
    return cached;
  }

  final fragmentType = convertTypeOrNull(
    fragment.typeCondition.on,
    context.schema.typeMap,
  ) as GraphQLNamedType?;
  return getFieldsAndFragmentNames(
    context,
    cachedFieldsAndFragmentNames,
    fragmentType,
    fragment.selectionSet,
  );
}