<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_referenced_fields_and_fragment_names( context: ValidationContext, cached_fields_and_fragment_names: Dict, fragment: FragmentDefinitionNode, ) -> Tuple[NodeAndDefCollection, List[str]]: """Get referenced fields and nested fragment names 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. """

    # Short-circuit building a type from the node if possible.
    cached = cached_fields_and_fragment_names.get(fragment.selection_set)
    if cached:
        return cached

    fragment_type = type_from_ast(context.schema, fragment.type_condition)
    return get_fields_and_fragment_names(
        context, cached_fields_and_fragment_names, fragment_type, fragment.selection_set
    )