o
    tBhN                     @   s   d dl mZmZmZmZ ddlmZmZmZm	Z	m
Z
mZmZ dgZeeee f Zdedeeef fddZdee d	ed
eddfddZG dd deZde
dee fddZdS )    )AnyDictListSet   )DocumentNodeFragmentDefinitionNodeFragmentSpreadNodeOperationDefinitionNodeSelectionSetNodeVisitorvisitseparate_operationsdocument_astreturnc                    s   g }i }| j D ]}t|tr|| qt|tr"t|j||jj< qi }|D ],t	  tjD ]}t
 || q1jrAjjnd}t fdd| j D d||< q'|S )a  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.
     c                    s.   g | ]}|u st |tr|jj v r|qS  )
isinstancer   namevalue).0nodedependencies	operationr   |/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/utilities/separate_operations.py
<listcomp>7   s    z'separate_operations.<locals>.<listcomp>)definitions)r   r   r
   appendr   collect_dependenciesselection_setr   r   setcollect_transitive_dependenciesr   )r   
operations	dep_graphdefinition_nodeseparated_document_astsfragment_nameoperation_namer   r   r   r      s0   

	collectedr$   	from_nameNc                 C   sF   || vr|  | ||}|dur|D ]}t| || qdS dS dS )zCollect transitive dependencies.

    From a dependency graph, collects a list of transitive dependencies by recursing
    through a dependency graph.
    N)addgetr"   )r)   r$   r*   immediate_depsto_namer   r   r   r"   E   s   

r"   c                       sB   e Zd ZU ee ed< d
 fddZdededdfdd	Z	  Z
S )DependencyCollectorr   r   Nc                    s   t    g | _| jj| _d S N)super__init__r   r   add_dependency)self	__class__r   r   r2   Y   s   
zDependencyCollector.__init__r   _argsc                 G   s   |  |jj d S r0   )r3   r   r   )r4   r   r7   r   r   r   enter_fragment_spread^   s   z)DependencyCollector.enter_fragment_spread)r   N)__name__
__module____qualname__r   str__annotations__r2   r	   r   r8   __classcell__r   r   r5   r   r/   V   s   
 r/   r    c                 C   s   t  }t| | |jS r0   )r/   r   r   )r    	collectorr   r   r   r   b   s   
r   )typingr   r   r   r   languager   r   r	   r
   r   r   r   __all__r<   DepGraphr   r"   r/   r   r   r   r   r   <module>   s     $
2
