o
    tBhSA                     @   s$  d dl mZ d dl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 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) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 dd	l7m7Z7 d
gZ8	dde2de9defdd
Z:dS )    )chain)castCallable
CollectionDictListUnion   )DirectiveLocationparse_value)inspect	Undefined)GraphQLArgumentGraphQLDirectiveGraphQLEnumTypeGraphQLEnumValueGraphQLFieldGraphQLInputFieldGraphQLInputObjectTypeGraphQLInputTypeGraphQLInterfaceTypeGraphQLListGraphQLNamedTypeGraphQLNonNullGraphQLObjectTypeGraphQLOutputTypeGraphQLScalarTypeGraphQLSchemaGraphQLTypeGraphQLUnionTypeTypeKindassert_interface_typeassert_nullable_typeassert_object_typeintrospection_typesis_input_typeis_output_typespecified_scalar_types   )IntrospectionDirectiveIntrospectionEnumTypeIntrospectionFieldIntrospectionInterfaceTypeIntrospectionInputObjectTypeIntrospectionInputValueIntrospectionObjectTypeIntrospectionQueryIntrospectionScalarTypeIntrospectionTypeIntrospectionTypeRefIntrospectionUnionType)value_from_astbuild_client_schemaFintrospectionassume_validreturnc                    s0  t | trt | dtstdt|  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dd}dtt	tf dt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d!d"}d#tdtffd$d%}tjj|tjj|tjj|tjj|tjj|tjj|id&tt	tf dtt t!f ffd'd(d)t"dt!ffd*d+d,t#t$ dtt t%f f fd-d.d/t$dt%ffd0d1 d2t#t$ dtt t&f ffd3d4d5t$dt&ffd6d7d8t'dt(ffd9d:fd;d<|d= D t)t*+ t,+ D ]\}	}
|	v rA|
|	< q4|d>}|d?u rOd?n|}|d@}|d?u r_d?n|}|dA}|d?u rod?n|}|dB}|rfdCdD|D ng }t-|||t./ ||dE|dFS )Ga*  Build a GraphQLSchema for use by client tools.

    Given the result of a client running the introspection query, creates and returns
    a GraphQLSchema instance which can be then used with all GraphQL-core 3 tools,
    but cannot be used to execute a query, as introspection does not represent the
    "resolver", "parse" or "serialize" functions or any other server-internal
    mechanisms.

    This function expects a complete introspection result. Don't forget to check the
    "errors" field of a server response before calling this function.
    __schemazInvalid or incomplete introspection result. Ensure that you are passing the 'data' attribute of an introspection response and no 'errors' were returned alongside: .type_refr9   c                    s   |  d}|tjjkr!|  d}|stdtt|}t|S |tjjkrA|  d}|s2tdtt|}|}t	t
|S tt| }  | S )NkindofTypez/Decorated type deeper than introspection query.)getr    LISTname	TypeErrorr   r3   r   NON_NULLr   r"   r2   )r<   r=   item_refnullable_refnullable_type)get_named_typeget_type |/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/utilities/build_client_schema.pyrH   Q   s    





z%build_client_schema.<locals>.get_typec                    sD   |  d}|stdt|  d  |}|s td| d|S )NrA   zUnknown type reference: r;   z,Invalid or incomplete schema, unknown type: zS. Ensure that a full introspection query is used in order to build a client schema.r?   rB   r   )r<   	type_nametype_)type_maprI   rJ   rG   c   s   


z+build_client_schema.<locals>.get_named_typec                       t  | S N)r#   r<   rH   rI   rJ   get_object_typeq   s   z,build_client_schema.<locals>.get_object_typec                    rO   rP   )r!   rQ   rR   rI   rJ   get_interface_typet   s   z/build_client_schema.<locals>.get_interface_typerM   c                    sB   | rd| v rd| v r  | d }|r|| S tdt|  d)NrA   r=   z~Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: r;   rK   )rM   builder)type_buildersrI   rJ   
build_typez   s   z'build_client_schema.<locals>.build_typescalar_introspectionc                 S   s   t | d | d| ddS )NrA   descriptionspecifiedByURL)rA   rY   specified_by_url)r   r?   )rX   rI   rI   rJ   build_scalar_def   s
   z-build_client_schema.<locals>.build_scalar_defimplementing_introspectionc                    sZ   |  d}|d u r| d tjjkrg S tdt|  dttt |} fdd|D S )N
interfacesr=   z)Introspection result missing interfaces: r;   c                       g | ]} |qS rI   rI   ).0	interfacerT   rI   rJ   
<listcomp>       zKbuild_client_schema.<locals>.build_implementations_list.<locals>.<listcomp>)	r?   r    	INTERFACErA   rB   r   r   r   r,   )r]   maybe_interfacesr^   rb   rI   rJ   build_implementations_list   s   
z7build_client_schema.<locals>.build_implementations_listobject_introspectionc                    .   t  d  d fdd fdddS )NrA   rY   c                          S rP   rI   rI   )rg   rh   rI   rJ   <lambda>       z?build_client_schema.<locals>.build_object_def.<locals>.<lambda>c                      rj   rP   rI   rI   )build_field_def_maprh   rI   rJ   rk      rl   rA   rY   r^   fields)r   r?   rh   rm   rg   rp   rJ   build_object_def      z-build_client_schema.<locals>.build_object_definterface_introspectionc                    ri   )NrA   rY   c                      rj   rP   rI   rI   )rg   rt   rI   rJ   rk      rl   zBbuild_client_schema.<locals>.build_interface_def.<locals>.<lambda>c                      rj   rP   rI   rI   )rm   rt   rI   rJ   rk      rl   rn   )r   r?   rt   rq   ru   rJ   build_interface_def   rs   z0build_client_schema.<locals>.build_interface_defunion_introspectionc                    sV   |  d}|d u rtdt|  dttt | t| d |  d fdddS )	NpossibleTypesz,Introspection result missing possibleTypes: r;   rA   rY   c                      s    fddD S )Nc                    r_   rI   rI   )r`   rM   rS   rI   rJ   rc      rd   zRbuild_client_schema.<locals>.build_union_def.<locals>.<lambda>.<locals>.<listcomp>rI   rI   )rS   possible_typesrI   rJ   rk      s    z>build_client_schema.<locals>.build_union_def.<locals>.<lambda>)rA   rY   types)r?   rB   r   r   r   r/   r   )rw   maybe_possible_typesry   )rz   rJ   build_union_def   s   
z,build_client_schema.<locals>.build_union_defenum_introspectionc                 S   sH   |  dd u rtdt|  dt| d |  ddd | d D dS )	N
enumValuesz)Introspection result missing enumValues: r;   rA   rY   c              	   S   s0   i | ]}|d  t |d  |d|ddqS )rA   rY   deprecationReason)valuerY   deprecation_reason)r   r?   )r`   value_introspectrI   rI   rJ   
<dictcomp>   s    z?build_client_schema.<locals>.build_enum_def.<locals>.<dictcomp>)rA   rY   values)r?   rB   r   r   )r~   rI   rI   rJ   build_enum_def   s   z+build_client_schema.<locals>.build_enum_definput_object_introspectionc                    sD     dd u rtdt  dt d   d fdddS )	NinputFieldsz*Introspection result missing inputFields: r;   rA   rY   c                      s    d S )Nr   rI   rI   )build_input_value_def_mapr   rI   rJ   rk      s    zEbuild_client_schema.<locals>.build_input_object_def.<locals>.<lambda>)rA   rY   ro   )r?   rB   r   r   r   )r   r   rJ   build_input_object_def   s   z3build_client_schema.<locals>.build_input_object_deftype_introspectionc                    s4   |  dd u rtd|  d fdd| d D S )Nro   z%Introspection result missing fields: r;   c                       i | ]	}|d   |qS rA   rI   )r`   field_introspectionbuild_fieldrI   rJ   r          zDbuild_client_schema.<locals>.build_field_def_map.<locals>.<dictcomp>)r?   rB   )r   r   rI   rJ   rm      s   

z0build_client_schema.<locals>.build_field_def_mapr   c                    s   t t| d }|}t|stdt| dt t|}| d}|d u r1tdt|  dt| || d| ddS )	NtypezAIntrospection must provide output type for fields, but received: r;   argsz)Introspection result missing field args: rY   r   )r   rY   r   )r   r2   r&   rB   r   r   r?   r   )r   r   rM   args_introspection)build_argument_def_maprH   rI   rJ   r      s,   

z(build_client_schema.<locals>.build_fieldargument_value_introspectionsc                        fdd| D S )Nc                    r   r   rI   )r`   argument_introspectionbuild_argumentrI   rJ   r     r   zGbuild_client_schema.<locals>.build_argument_def_map.<locals>.<dictcomp>rI   )r   r   rI   rJ   r     s   
z3build_client_schema.<locals>.build_argument_def_mapr   c                    |   t t| d } |}t|stdt| dt t|}| d}|d u r)tntt	||}t
||| d| ddS )Nr   zCIntrospection must provide input type for arguments, but received: r;   defaultValuerY   r   default_valuerY   r   )r   r2   r%   rB   r   r   r?   r   r5   r   r   )r   r   rM   default_value_introspectionr   rR   rI   rJ   r     (   

z+build_client_schema.<locals>.build_argumentinput_value_introspectionsc                    r   )Nc                    r   r   rI   )r`   input_value_introspectionbuild_input_valuerI   rJ   r   8  s    zJbuild_client_schema.<locals>.build_input_value_def_map.<locals>.<dictcomp>rI   )r   r   rI   rJ   r   5  s   
z6build_client_schema.<locals>.build_input_value_def_mapr   c                    r   )Nr   zFIntrospection must provide input type for input fields, but received: r;   r   rY   r   r   )r   r2   r%   rB   r   r   r?   r   r5   r   r   )r   r   rM   r   r   rR   rI   rJ   r   ?  r   z.build_client_schema.<locals>.build_input_valuedirective_introspectionc              
      s   |  dd u rtdt|  d|  dd u r"tdt|  dt| d |  d|  dd	tttt |  d | d d
S )Nr   z-Introspection result missing directive args: r;   	locationsz2Introspection result missing directive locations: rA   rY   isRepeatableF)rA   rY   is_repeatabler   r   )r?   rB   r   r   listr   r   r
   )r   )r   rI   rJ   build_directiveX  s0   

z,build_client_schema.<locals>.build_directivec                    r   r   rI   )r`   r   )rW   rI   rJ   r   s  r   z'build_client_schema.<locals>.<dictcomp>r{   	queryTypeNmutationTypesubscriptionType
directivesc                    r_   rI   rI   )r`   r   )r   rI   rJ   rc     s    z'build_client_schema.<locals>.<listcomp>rY   )querymutationsubscriptionr{   r   rY   r8   )0
isinstancedictr?   rB   r   r3   r   r2   r   r/   r   r,   r   r1   r   r   r   r4   r   r*   r   r-   r   r    SCALARrA   OBJECTre   UNIONENUMINPUT_OBJECTr   strr   r+   r   r.   r   r   r)   r   r   r'   itemsr$   r   r   r   )r7   r8   schema_introspectionr\   rr   rv   r}   r   r   std_type_namestd_typequery_type_ref
query_typemutation_type_refmutation_typesubscription_type_refsubscription_typedirective_introspectionsr   rI   )r   r   r   r   rm   rg   r   r   rW   rT   rG   rS   rH   rV   rN   rJ   r6   5   s   

	

	













N)F);	itertoolsr   typingr   r   r   r   r   r   languager
   r   pyutilsr   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%   r&   r'   get_introspection_queryr)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   __all__boolr6   rI   rI   rI   rJ   <module>   s      p8