o
    tBh!                     @   s  d dl mZmZmZmZmZmZmZmZm	Z	 ddl
mZ ddlmZmZmZmZmZ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mZ ddlm Z m!Z! g dZ"eeef Z#G dd	 d	eZ$G d
d deZ%G dd dZ&G dd de&Z'G dd de&Z(dS )    )	AnyCallableDictList
NamedTupleOptionalSetUnioncast   )GraphQLError)	DocumentNodeFragmentDefinitionNodeFragmentSpreadNodeOperationDefinitionNodeSelectionSetNodeVariableNodeVisitorVisitorActionvisit)GraphQLArgumentGraphQLCompositeTypeGraphQLDirectiveGraphQLEnumValueGraphQLFieldGraphQLInputTypeGraphQLOutputTypeGraphQLSchema)TypeInfoTypeInfoVisitor)ASTValidationContextSDLValidationContextValidationContextVariableUsageVariableUsageVisitorc                   @   s*   e Zd ZU eed< ee ed< eed< dS )r#   nodetypedefault_valueN)__name__
__module____qualname__r   __annotations__r   r   r    r,   r,   |/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/validation/validation_context.pyr#   &   s   
 r#   c                       s\   e Zd ZU dZee ed< def fddZde	de
fdd	Zd
ede	de
fddZ  ZS )r$   z3Visitor adding all variable usages to a given list.usages	type_infoc                    s$   t    g | _| jj| _|| _d S N)super__init__r.   append_append_usage
_type_info)selfr/   	__class__r,   r-   r2   1   s   


zVariableUsageVisitor.__init___argsreturnc                 G   s   | j S r0   )SKIP)r6   r9   r,   r,   r-   enter_variable_definition7   s   z.VariableUsageVisitor.enter_variable_definitionr%   c                 G   s(   | j }t|| | }| | d S r0   )r5   r#   get_input_typeget_default_valuer4   )r6   r%   r9   r/   usager,   r,   r-   enter_variable:   s   
z#VariableUsageVisitor.enter_variable)r(   r)   r*   __doc__r   r#   r+   r   r2   r   r   r<   r   r@   __classcell__r,   r,   r7   r-   r$   ,   s   
 r$   c                   @   s   e Zd ZU dZeed< eeee	f  ed< ee
ee f ed< eeee	 f ed< dedeegdf d	dfd
dZded	dfddZded	dfddZded	ee	 fddZde
d	ee fddZded	ee	 fddZdS )r    zUtility class providing a context for validation of an AST.

    An instance of this class is passed as the context attribute to all Validators,
    allowing access to commonly useful contextual information from within a validation
    rule.
    document
_fragments_fragment_spreads!_recursively_referenced_fragmentsaston_errorNr:   c                 C   s"   || _ || _d | _i | _i | _d S r0   )rC   rH   rD   rE   rF   )r6   rG   rH   r,   r,   r-   r2   S   s
   
zASTValidationContext.__init__errorc                 C   s   d S r0   r,   r6   rI   r,   r,   r-   rH   \   s   zASTValidationContext.on_errorc                 C   s   |  | d S r0   )rH   rJ   r,   r,   r-   report_error_   s   z!ASTValidationContext.report_errornamec                 C   s0   | j }|d u rdd | jjD }|| _ ||S )Nc                 S   s    i | ]}t |tr|jj|qS r,   )
isinstancer   rL   value).0	statementr,   r,   r-   
<dictcomp>e   s    z5ASTValidationContext.get_fragment.<locals>.<dictcomp>)rD   rC   definitionsget)r6   rL   	fragmentsr,   r,   r-   get_fragmentb   s   
z!ASTValidationContext.get_fragmentr%   c           
      C   s   | j |}|d u r@g }|j}|g}|j}|j}|r;| }|jD ]}t|tr,|| q tt|j	}	|	r8||	 q |s|| j |< |S r0   )
rE   rS   r3   pop
selectionsrM   r   r
   NodeWithSelectionSetselection_set)
r6   r%   spreadsappend_spreadsets_to_visit
append_setpop_setvisited_set	selectionset_to_visitr,   r,   r-   get_fragment_spreadsn   s.   



z)ASTValidationContext.get_fragment_spreads	operationc                 C   s   | j |}|d u rSg }|j}t }|j}|jg}|j}|j}| j}	| j}
|rN| }|
|D ]}|j	j
}||vrK|| |	|}|rK|| ||j q.|s'|| j |< |S r0   )rF   rS   r3   setaddrY   rV   rU   rb   rL   rN   )r6   rc   rT   append_fragmentcollected_namesadd_namenodes_to_visitappend_nodepop_noderU   rb   visited_nodespread	frag_namefragmentr,   r,   r-   $get_recursively_referenced_fragments   s2   


z9ASTValidationContext.get_recursively_referenced_fragments)r(   r)   r*   rA   r   r+   r   r   strr   r   r   r   r   r   r   r2   rH   rK   rU   rb   rp   r,   r,   r,   r-   r    C   s0   
 

	r    c                       sN   e Zd ZU dZee ed< dedee dee	gdf ddf fddZ
  ZS )	r!   zUtility class providing a context for validation of an SDL AST.

    An instance of this class is passed as the context attribute to all Validators,
    allowing access to commonly useful contextual information from within a validation
    rule.
    schemarG   rH   Nr:   c                    s   t  || || _d S r0   )r1   r2   rr   )r6   rG   rr   rH   r7   r,   r-   r2      s   
zSDLValidationContext.__init__)r(   r)   r*   rA   r   r   r+   r   r   r   r2   rB   r,   r,   r7   r-   r!      s   
 r!   c                
       s6  e Zd ZU dZeed< eed< eee	e
 f ed< eee	e
 f ed< dedededeegd	f d
d	f
 fddZded
e	e
 fddZded
e	e
 fddZd
ee fddZd
ee fddZd
ee fddZd
ee fddZd
ee fddZd
ee fddZd
ee fdd Zd
ee  fd!d"Z!  Z"S )#r"   a  Utility class providing a context for validation using a GraphQL schema.

    An instance of this class is passed as the context attribute to all Validators,
    allowing access to commonly useful contextual information from within a validation
    rule.
    rr   r5   _variable_usages_recursive_variable_usagesrG   r/   rH   Nr:   c                    s*   t  || || _|| _i | _i | _d S r0   )r1   r2   rr   r5   rs   rt   )r6   rr   rG   r/   rH   r7   r,   r-   r2      s
   
zValidationContext.__init__r%   c                 C   sD   | j |}|d u r t| j}t|t| j| |j}|| j |< |S r0   )rs   rS   r$   r5   r   r   r.   )r6   r%   r.   usage_visitorr,   r,   r-   get_variable_usages   s   

z%ValidationContext.get_variable_usagesrc   c                 C   sN   | j |}|d u r%| j}||}| |D ]	}||| q|| j |< |S r0   )rt   rS   rv   rp   extend)r6   rc   r.   rv   ro   r,   r,   r-   get_recursive_variable_usages   s   
z/ValidationContext.get_recursive_variable_usagesc                 C   
   | j  S r0   )r5   get_typer6   r,   r,   r-   rz         
zValidationContext.get_typec                 C   ry   r0   )r5   get_parent_typer{   r,   r,   r-   r}      r|   z!ValidationContext.get_parent_typec                 C   ry   r0   )r5   r=   r{   r,   r,   r-   r=      r|   z ValidationContext.get_input_typec                 C   ry   r0   )r5   get_parent_input_typer{   r,   r,   r-   r~      r|   z'ValidationContext.get_parent_input_typec                 C   ry   r0   )r5   get_field_defr{   r,   r,   r-   r      r|   zValidationContext.get_field_defc                 C   ry   r0   )r5   get_directiver{   r,   r,   r-   r      r|   zValidationContext.get_directivec                 C   ry   r0   )r5   get_argumentr{   r,   r,   r-   r      r|   zValidationContext.get_argumentc                 C   ry   r0   )r5   get_enum_valuer{   r,   r,   r-   r      r|   z ValidationContext.get_enum_value)#r(   r)   r*   rA   r   r+   r   r   rX   r   r#   r   r   r   r   r2   rv   rx   r   r   rz   r   r}   r   r=   r~   r   r   r   r   r   r   r   r   rB   r,   r,   r7   r-   r"      s>   
 	
r"   N))typingr   r   r   r   r   r   r   r	   r
   rI   r   languager   r   r   r   r   r   r   r   r   r&   r   r   r   r   r   r   r   r   	utilitiesr   r   __all__rX   r#   r$   r    r!   r"   r,   r,   r,   r-   <module>   s   , ,(
]