o
    tBhpj                     @   s"  U 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mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ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+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZS ddlTmTZT d	d
gZU		ddeBdedeVdeVdeBf
dd	ZW	ddeCdedeVdeCfdd
ZXi eSeRZYe	eZee<e?f f e[d< deeeef de
eZ fddZ\dee e!f de
eZ fddZ]dS )    )defaultdict)
AnyCallable
CollectionDefaultDictDictListMappingOptionalUnioncast   )DirectiveDefinitionNodeDirectiveLocationDocumentNodeEnumTypeDefinitionNodeEnumTypeExtensionNodeEnumValueDefinitionNodeFieldDefinitionNodeInputObjectTypeDefinitionNodeInputObjectTypeExtensionNodeInputValueDefinitionNodeInterfaceTypeDefinitionNodeInterfaceTypeExtensionNodeListTypeNodeNamedTypeNodeNonNullTypeNodeObjectTypeDefinitionNodeObjectTypeExtensionNodeOperationTypeScalarTypeDefinitionNodeScalarTypeExtensionNodeSchemaExtensionNodeSchemaDefinitionNodeTypeDefinitionNodeTypeExtensionNodeTypeNodeUnionTypeDefinitionNodeUnionTypeExtensionNode)inspectmerge_kwargs)'GraphQLArgumentGraphQLArgumentMapGraphQLDeprecatedDirectiveGraphQLDirectiveGraphQLEnumTypeGraphQLEnumValueGraphQLEnumValueMapGraphQLFieldGraphQLFieldMapGraphQLInputFieldGraphQLInputObjectTypeGraphQLInputTypeGraphQLInputFieldMapGraphQLInterfaceTypeGraphQLListGraphQLNamedTypeGraphQLNonNullGraphQLNullableTypeGraphQLObjectTypeGraphQLOutputTypeGraphQLScalarTypeGraphQLSchemaGraphQLSchemaKwargsGraphQLSpecifiedByDirectiveGraphQLTypeGraphQLUnionTypeassert_schemais_enum_typeis_input_object_typeis_interface_typeis_list_typeis_non_null_typeis_object_typeis_scalar_typeis_union_typeis_introspection_typeis_specified_scalar_typeintrospection_typesspecified_scalar_types   )value_from_astextend_schemaextend_schema_implFschemadocument_astassume_validassume_valid_sdlreturnc                 C   sf   t |  t|tstd|s|sddlm} |||  |  }t|||}||u r,| S tdi |S )aO  Extend the schema with extensions from a given document.

    Produces a new schema given an existing schema and a document which may contain
    GraphQL type extensions and definitions. The original schema will remain unaltered.

    Because a schema represents a graph of references, a schema cannot be extended
    without effectively making an entire copy. We do not know until it's too late if
    subgraphs remain unchanged.

    This algorithm copies the provided schema, applying extensions while producing the
    copy. The original schema remains unaltered.

    When extending a schema with a known valid extension, it might be safe to assume the
    schema is valid. Set ``assume_valid`` to ``True`` to assume the produced schema is
    valid. Set ``assume_valid_sdl`` to ``True`` to assume it is already a valid SDL
    document.
    z Must provide valid Document AST.r   )assert_valid_sdl_extensionN )	rE   
isinstancer   	TypeErrorvalidation.validater[   	to_kwargsrU   r@   )rV   rW   rX   rY   r[   schema_kwargsextended_kwargsr\   r\   v/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/utilities/extend_schema.pyrT   ^   s   


ra   c                    s2  g }t tg }d}g }|jD ];}t|tr|}qt|tr$|| qt|tr/|| qt|tr@|j	j
}| | qt|trJ|| qsW|sW|sW|sW|sW| S dtdtffdddtdtffdddtdtffd	d
dtdtf	fdd}	dtdtffdddtdtffdd	dtdtffdddtdtf
fdddtdtf
fdddtdtffdddtdtffdd
dtdtffdddttttf  dtttf ffd d!}
d"tdtffd#d$d"tdtffd%d&d"tdtf fd'd(dtttttt f  dt!f fd)d*d+t"tt#  dt$ffd,d- dttt%t&f  dt'ffd.d/dttt(t)f  dt*fd0d1dtttttt f  dt+t ffd2d3dttt,t-f  dt+t ffd4d5d6tdtffd7d8}d6tdtffd9d:}d6t(dtffd;d<}d6t,dtffd=d>}d6t.dtffd?d@}d6t%dtffdAdB}t/tt0t1tgtf f ||||||dCd6tdtffdDdE}i | dF pdGD ]
}|	||j	< q|D ]}|j	j
}t23|p|||< qi }tD ]}| |j
 }|r8|||< q(|rE|4|
|g |rO|4|
| |j3}t5|tj6|tj7|tj8t9: t9fdHdI| dJ D t9fdKdI|D  |r|j;r|j;j
ndi |p| d6 | dL t9| |dM
S )NziExtend the given schema arguments with extensions from a given document.

    For internal use only.
    Ntype_rZ   c                    s4   t | rt| jS t| rt| jS  | S N)rI   r9   of_typerJ   r;   rd   )replace_named_typereplace_typer\   rc   ri      s
   z(extend_schema_impl.<locals>.replace_typec                    s
    | j  S re   )namerg   type_mapr\   rc   rh      s   
z.extend_schema_impl.<locals>.replace_named_type	directivec                    s4   |   }tdi t| fdd|d  D dS )Nc                       i | ]	\}}| |qS r\   r\   .0rj   arg
extend_argr\   rc   
<dictcomp>       zAextend_schema_impl.<locals>.replace_directive.<locals>.<dictcomp>args)rv   r\   )r`   r.   r*   items)rm   kwargsrr   r\   rc   replace_directive   s   z-extend_schema_impl.<locals>.replace_directivec                    s   t | st| r
| S t| rtt| } | S t| r$tt| } | S t| r1tt| } | S t	| r>tt
| } | S t| rKtt| }  | S t| rXtt| } | S tdt|  d)NzUnexpected type: .)rN   rO   rL   r   r?   rK   r=   rH   r8   rM   rD   rF   r/   rG   r5   r^   r)   rg   )extend_enum_typeextend_input_object_typeextend_interface_typeextend_object_typeextend_scalar_typeextend_union_typer\   rc   extend_named_type   s*   





z-extend_schema_impl.<locals>.extend_named_typec              	      F   |   td   tdi t fddd   dS )Nrj   c                      s&   i fddd   D  S )Nc              
      s2   i | ]\}}|t di t|  |jd qS )rg   r\   )r4   r*   r`   typerp   rj   fieldri   r\   rc   rt      s    zZextend_schema_impl.<locals>.extend_input_object_type.<locals>.<lambda>.<locals>.<dictcomp>fieldsrw   r\   )build_input_field_map
extensionsrx   ri   r\   rc   <lambda>   s    


zFextend_schema_impl.<locals>.extend_input_object_type.<locals>.<lambda>extension_ast_nodes)r   r   r\   )r`   tupler5   r*   rg   )r   ri   type_extensions_mapr   rx   rc   r|      s   
z4extend_schema_impl.<locals>.extend_input_object_typec                    sH   |   }t|d  }tdi t|i |d  ||d | dS )Nrj   valuesr   )r   r   r\   )r`   r   r/   r*   )rd   rx   r   build_enum_value_mapr   r\   rc   r{     s   
z,extend_schema_impl.<locals>.extend_enum_typec                    sV   |   }t |d  }|d }|D ]}t|p|}qtdi t|||d | dS )Nrj   specified_by_urlr   )r   r   r\   )r`   r   get_specified_by_urlr?   r*   )rd   rx   r   r   extension_noder   r\   rc   r     s   
z.extend_schema_impl.<locals>.extend_scalar_typec              
      V   |   td   tdi t fdd fddd   dS )Nrj   c                         fddd D   S )Nc                       g | ]	}t t |qS r\   r   r8   rp   	interfacerh   r\   rc   
<listcomp>(      zTextend_schema_impl.<locals>.extend_object_type.<locals>.<lambda>.<locals>.<listcomp>
interfacesr\   r\   build_interfacesr   rx   rh   r\   rc   r   (  
   
 z@extend_schema_impl.<locals>.extend_object_type.<locals>.<lambda>c                      &   i fddd   D  S )Nc                    rn   r\   r\   r   extend_fieldr\   rc   rt   .      zTextend_schema_impl.<locals>.extend_object_type.<locals>.<lambda>.<locals>.<dictcomp>r   r   r\   build_field_mapr   r   rx   r\   rc   r   -      

r   r   r   r   r\   )r`   r   r=   r*   rg   r   r   r   rh   r   r   rc   r~   !     
z.extend_schema_impl.<locals>.extend_object_typec              
      r   )Nrj   c                      r   )Nc                    r   r\   r   r   r   r\   rc   r   @  r   zWextend_schema_impl.<locals>.extend_interface_type.<locals>.<lambda>.<locals>.<listcomp>r   r\   r\   r   r\   rc   r   @  r   zCextend_schema_impl.<locals>.extend_interface_type.<locals>.<lambda>c                      r   )Nc                    rn   r\   r\   r   r   r\   rc   rt   F  r   zWextend_schema_impl.<locals>.extend_interface_type.<locals>.<lambda>.<locals>.<dictcomp>r   r   r\   r   r\   rc   r   E  r   r   r   r\   )r`   r   r8   r*   rg   r   r   rc   r}   9  r   z1extend_schema_impl.<locals>.extend_interface_typec              	      r   )Nrj   c                      r   )Nc                    r   r\   )r   r=   )rp   member_typer   r\   rc   r   W  r   zSextend_schema_impl.<locals>.extend_union_type.<locals>.<lambda>.<locals>.<listcomp>typesr\   r\   )build_union_typesr   rx   rh   r\   rc   r   W  r   z?extend_schema_impl.<locals>.extend_union_type.<locals>.<lambda>r   )r   r   r\   )r`   r   rD   r*   rg   )r   rh   r   r   rc   r   P  s   
z-extend_schema_impl.<locals>.extend_union_typer   c              	      s6   t di t|  | j fdd| j D dS )Nc                    rn   r\   r\   ro   rr   r\   rc   rt   f  ru   z<extend_schema_impl.<locals>.extend_field.<locals>.<dictcomp>)rd   rv   r\   )r2   r*   r`   r   rv   rw   )r   )rs   ri   r\   rc   r   a  s   z(extend_schema_impl.<locals>.extend_fieldrq   c                    s    t di t|   | jdS )Nrg   r\   )r+   r*   r`   r   )rq   r   r\   rc   rs   j  s   z&extend_schema_impl.<locals>.extend_argnodesc                    s    fdd| D S )Nc                    s*   i | ]}|j pg D ]	}|j |jq	qS r\   )operation_types	operationr   )rp   nodeoperation_typeget_named_typer\   rc   rt   y  s    zCextend_schema_impl.<locals>.get_operation_types.<locals>.<dictcomp>r\   )r   r   r\   rc   get_operation_typess  s   
z/extend_schema_impl.<locals>.get_operation_typesr   c                    s4   | j j}t|p |}|std| d|S )NzUnknown type: 'z'.)rj   valuestd_type_mapgetr^   )r   rj   rd   rk   r\   rc   r     s
   z*extend_schema_impl.<locals>.get_named_typec                    sD   t | trt| jS t | trttt| jS  tt| S re   )	r]   r   r9   r   r   r;   r   r<   r   )r   )r   get_wrapped_typer\   rc   r     s   

z,extend_schema_impl.<locals>.get_wrapped_typec                    s>   dd | j D }t| jj| jr| jjnd || j | j| dS )Nc                 S   s   g | ]}t |j qS r\   )r   r   )rp   r   r\   r\   rc   r     s    z?extend_schema_impl.<locals>.build_directive.<locals>.<listcomp>)rj   description	locationsis_repeatablerv   ast_node)r   r.   rj   r   r   
repeatable	arguments)r   r   )build_argument_mapr\   rc   build_directive  s   z+extend_schema_impl.<locals>.build_directivec              	      s`   i }| D ])}|j p
g D ]!}ttt|j|jr|jjnd  |jt||d||j	j< qq|S )N)rd   r   rv   deprecation_reasonr   )
r   r2   r   r>   r   r   r   r   get_deprecation_reasonrj   )r   	field_mapr   r   )r   r   r\   rc   r     s   
z+extend_schema_impl.<locals>.build_field_maprv   c                    sZ   i }| pg D ]$}t t |j}t||jr|jjnd t|j|t||d||j	j< q|S N)rd   r   default_valuer   r   )
r   r6   r   r+   r   r   rS   r   r   rj   )rv   arg_maprq   rd   r   r\   rc   r     s   
z.extend_schema_impl.<locals>.build_argument_mapc              	      sf   i }| D ],}|j p
g D ]$}tt |j}t||jr|jjnd t|j|t	||d||j
j< qq|S r   )r   r   r6   r   r4   r   r   rS   r   r   rj   )r   input_field_mapr   r   rd   r   r\   rc   r     s   
z1extend_schema_impl.<locals>.build_input_field_mapc                 S   sP   i }| D ]!}|j p
g D ]}|jj}t||jr|jjnd t||d||< qq|S )N)r   r   r   r   )r   rj   r   r0   r   r   )r   enum_value_mapr   r   
value_namer\   r\   rc   r     s   z0extend_schema_impl.<locals>.build_enum_value_mapc                    6   g }| D ]}|j p
g D ]}|tt | qq|S re   )r   appendr   r8   )r   r   r   rd   r   r\   rc   r     s   
z,extend_schema_impl.<locals>.build_interfacesc                    r   re   )r   r   r   r=   )r   r   r   rd   r   r\   rc   r     s   z-extend_schema_impl.<locals>.build_union_typesr   c                    P   | j j }| g| t| j j| jr| jjnd  fdd fdd| |dS )Nc                          S re   r\   r\   	all_nodesr   r\   rc   r         z?extend_schema_impl.<locals>.build_object_type.<locals>.<lambda>c                      r   re   r\   r\   r   r   r\   rc   r     r   rj   r   r   r   r   r   )rj   r   r=   r   r   extension_nodesr   r   r   r   rc   build_object_type  s   z-extend_schema_impl.<locals>.build_object_typec                    r   )Nc                      r   re   r\   r\   r   r\   rc   r   '  r   zBextend_schema_impl.<locals>.build_interface_type.<locals>.<lambda>c                      r   re   r\   r\   r   r\   rc   r   (  r   r   )rj   r   r8   r   r   r   r   rc   build_interface_type  s   z0extend_schema_impl.<locals>.build_interface_typec                    s>   | j j }| g|}t| j j| jr| jjnd  || |dS )N)rj   r   r   r   r   )rj   r   r/   r   )r   r   r   r   r\   rc   build_enum_type-  s   z+extend_schema_impl.<locals>.build_enum_typec                    D   | j j }| g| t| j j| jr| jjnd  fdd| |dS )Nc                      r   re   r\   r\   )r   r   r\   rc   r   D  r   z>extend_schema_impl.<locals>.build_union_type.<locals>.<lambda>)rj   r   r   r   r   )rj   r   rD   r   r   )r   r   r   rc   build_union_type;  s   z,extend_schema_impl.<locals>.build_union_typec                    s4    | j j }t| j j| jr| jjnd t| | |dS )N)rj   r   r   r   r   )rj   r   r?   r   r   r   r   r\   rc   build_scalar_typeI  s   z-extend_schema_impl.<locals>.build_scalar_typec                    r   )Nc                      r   re   r\   r\   )r   r   r\   rc   r   ]  r   zEextend_schema_impl.<locals>.build_input_object_type.<locals>.<lambda>)rj   r   r   r   r   )rj   r   r5   r   r   )r   r   r   rc   build_input_object_typeS  s   z3extend_schema_impl.<locals>.build_input_object_type)object_type_definitioninterface_type_definitionenum_type_definitionunion_type_definitionscalar_type_definitioninput_object_type_definitionc                    s8   z
 | j  }W || S  ty   tdt|  dw )Nz!Unexpected type definition node: rz   )kindKeyErrorr^   r)   )r   build_function)build_type_for_kindr\   rc   
build_typen  s   z&extend_schema_impl.<locals>.build_typer   r\   c                 3       | ]} |V  qd S re   r\   rp   rm   )ry   r\   rc   	<genexpr>  s    
z%extend_schema_impl.<locals>.<genexpr>
directivesc                 3   r   re   r\   r   )r   r\   rc   r     s    r   )
querymutationsubscriptionr   r   r   r   r   r   rX   )<r   listdefinitionsr]   r#   r"   r   r$   r%   rj   r   r   rC   r:   r.   r5   r/   r?   r=   r8   rD   r2   r+   r   r   r   r   r   r&   r   r   r   r   r3   r
   r   r,   r   r   r7   r   r   r1   r   r'   r(   r    r   strr   r   r   updaterA   QUERYMUTATIONSUBSCRIPTIONr   r   r   )ra   rW   rX   	type_defsdirective_defs
schema_defschema_extensionsdef_extended_type_namer   r   r   r   r   r   r   r   r   existing_type	type_noderj   r   r   original_typeget_operationr\   )r   r   r   r   r   r   r   r   rs   r{   r   r|   r}   r~   r   r   r   r   ry   rh   ri   r   rl   rc   rU      sJ  






 			
		


	


r   r   c                 C   &   ddl m} |t| }|r|d S dS )zCGiven a field or enum value node, get deprecation reason as string.r   get_directive_valuesreasonN)	executionr  r-   )r   r  
deprecatedr\   r\   rc   r        
r   c                 C   r  )zDGiven a scalar node, return the string value for the specifiedByURL.r   r  urlN)r
  r  rB   )r   r  r   r\   r\   rc   r     r  r   N)FF)F)^collectionsr   typingr   r   r   r   r   r   r	   r
   r   r   languager   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   pyutilsr)   r*   r   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rS   __all__boolrT   rU   r   r   __annotations__r   r   r\   r\   r\   rc   <module>   sf    0t)	
+
    #


