o
    tBh5                     @   sN  d dl mZmZmZmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZmZ ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZmZ g dZG dd deZ			ddededeeee   dee dee dee fddZ		d dedee deeee   dee fddZ deddfddZ!dededdfddZ"dS )!    )
CollectionListOptionalType   )GraphQLError)DocumentNodeParallelVisitorvisit)inspectis_collection)GraphQLSchemaassert_valid_schema)TypeInfoTypeInfoVisitor   )ASTValidationRule)specified_rulesspecified_sdl_rules)SDLValidationContextValidationContext)assert_valid_sdlassert_valid_sdl_extensionvalidatevalidate_sdlc                   @   s   e Zd ZdZdS )ValidationAbortedErrorz?Error when a validation has been aborted (error limit reached).N)__name__
__module____qualname____doc__ r    r    r/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/validation/validate.pyr      s    r   Nschemadocument_astrules
max_errors	type_inforeturnc                    s
  |rt |tstdt|  du rdn	t tstd|du r(t| }nt |ts7tdt| d|du r>t}nt|rKt	dd |D sOtd	g d
t
ddffdd}t| |||  fdd|D }zt|t|t| W S  ty   Y S w )a  Implements the "Validation" section of the spec.

    Validation runs synchronously, returning a list of encountered errors, or an empty
    list if no errors were encountered and the document is valid.

    A list of specific validation rules may be provided. If not provided, the default
    list of rules defined by the GraphQL specification will be used.

    Each validation rule is a ValidationRule object which is a visitor object that holds
    a ValidationContext (see the language/visitor API). Visitor methods are expected to
    return GraphQLErrors, or lists of GraphQLErrors when invalid.

    Validate will stop validation after a ``max_errors`` limit has been reached.
    Attackers can send pathologically invalid queries to induce a DoS attack,
    so by default ``max_errors`` set to 100 errors.

    Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
    zMust provide document.Nd   z6The maximum number of errors must be passed as an int.zNot a TypeInfo object: .c                 s   s$    | ]}t |tot|tV  qd S N)
isinstancetype
issubclassr   .0ruler    r    r!   	<genexpr>:   s    
zvalidate.<locals>.<genexpr>zHRules must be specified as a collection of ASTValidationRule subclasses.errorr'   c                    s,   t  kr td t |  d S )NzDToo many validation errors, error limit reached. Validation aborted.)lenappendr   r   )r2   )errorsr%   r    r!   on_errorC   s   zvalidate.<locals>.on_errorc                       g | ]}| qS r    r    r.   contextr    r!   
<listcomp>R       zvalidate.<locals>.<listcomp>)r+   r   	TypeErrorr   intr   r   r   r   allr   r   r
   r   r	   r   )r"   r#   r$   r%   r&   r6   visitorsr    )r9   r5   r%   r!   r      s<   


r   schema_to_extendc                    sB   g }t | ||j |du rt} fdd|D }t| t| |S )z:Validate an SDL document.

    For internal use only.
    Nc                    r7   r    r    r.   r8   r    r!   r:   i   r;   z validate_sdl.<locals>.<listcomp>)r   r4   r   r
   r	   )r#   r@   r$   r5   r?   r    r8   r!   r   \   s   	r   c                 C   s(   t | }|rtddd |D dS )zAssert document is valid SDL.

    Utility function which asserts a SDL document is valid by throwing an error if it
    is invalid.
    

c                 s       | ]}|j V  qd S r*   messager/   r2   r    r    r!   r1   w       z#assert_valid_sdl.<locals>.<genexpr>Nr   r<   join)r#   r5   r    r    r!   r   n   s   r   c                 C   s*   t | |}|rtddd |D dS )zAssert document is a valid SDL extension.

    Utility function which asserts a SDL document is valid by throwing an error if it
    is invalid.
    rA   c                 s   rB   r*   rC   rE   r    r    r!   r1      rF   z-assert_valid_sdl_extension.<locals>.<genexpr>NrG   )r#   r"   r5   r    r    r!   r   z   s   
	r   )NNN)NN)#typingr   r   r   r   r2   r   languager   r	   r
   pyutilsr   r   r,   r   r   	utilitiesr   r   r$   r   r   r   validation_contextr   r   __all__RuntimeErrorr   r=   r   r   r   r   r    r    r    r!   <module>   s\    
K
