def separate_operations(document_ast: DocumentNode) -> Dict[str, DocumentNode]:
    """Separate operations in a given AST document.

    This function accepts a single AST document which may contain many operations and
    fragments and returns a collection of AST documents each of which contains a single
    operation as well the fragment definitions it refers to.
    """

    # Populate metadata and build a dependency graph.
    visitor = SeparateOperations()
    visit(document_ast, visitor)
    operations = visitor.operations
    fragments = visitor.fragments
    positions = visitor.positions
    dep_graph = visitor.dep_graph

    # For each operation, produce a new synthesized AST which includes only what is
    # necessary for completing that operation.
    separated_document_asts = {}
    for operation in operations:
        operation_name = op_name(operation)
        dependencies: Set[str] = set()
        collect_transitive_dependencies(dependencies, dep_graph, operation_name)

        # The list of definition nodes to be included for this operation, sorted to
        # retain the same order as the original document.
        definitions: List[ExecutableDefinitionNode] = [operation]
        for name in dependencies:
            definitions.append(fragments[name])
            definitions.sort(key=lambda n: positions.get(n, 0))

        separated_document_asts[operation_name] = DocumentNode(definitions=definitions)

    return separated_document_asts
Separate operations in a given AST document.

    This function accepts a single AST document which may contain many operations and
    fragments and returns a collection of AST documents each of which contains a single
    operation as well the fragment definitions it refers to.