o
    tBh                     @   s  d Z ddlZddlZddl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 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,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZF dd	lGmHZH eIeJZKeLd
ZMde	dee9 fddZNde	de dee9 fddZOdddddefddZPG dd dZQG dd deZRG dd deRZSG dd deRZTG dd  d eSeTZUG d!d" d"eUZVG d#d$ d$eUZWG d%d& d&eUZXG d'd( d(ZYG d)d* d*ZZG d+d, d,Z[G d-d. d.eZ\G d/d0 d0eRZ]G d1d2 d2eRZ^G d3d4 d4e\Z_G d5d6 d6e_e^Z`G d7d8 d8e`ZaG d9d: d:e\e]ZbG d;d< d<e\e]eSZcdS )=a  
.. image:: http://www.plantuml.com/plantuml/png/ZLAzJWCn3Dxz51vXw1im50ag8L4XwC1OkLTJ8gMvAd4GwEYxGuC8pTbKtUxy_TZEvsaIYfAt7e1MII9rWfsdbF1cSRzWpvtq4GT0JENduX8GXr_g7brQlf5tw-MBOx_-HlS0LV_Kzp8xr1kZav9PfCsMWvolEA_1VylHoZCExKwKv4Tg2s_VkSkca2kof2JDb0yxZYIk3qMZYUe1B1uUZOROXn96pQMugEMUdRnUUqUf6DBXQyIz2zu5RlgUQAFVNYaeRfBI79_JrUTaeg9JZFQj5MmUc69PDmNGE2iU61fDgfri3x36gxHw3gDHD6xqqQ7P4vjKqz2-602xtkO7uo17SCLhVSv25VjRjUAFcUE73Sspb8ADBl8gTT7j2cFAOPst_Wi0  # noqa
    :alt: UML diagram
    N)ABCabstractmethod)isfinite)AnyDictIterableMappingOptionalTupleUnioncast)3ArgumentNodeBooleanValueNodeDocumentNodeEnumValueNode	FieldNodeFloatValueNodeFragmentDefinitionNodeFragmentSpreadNodeGraphQLArgumentGraphQLEnumTypeGraphQLErrorGraphQLField	GraphQLIDGraphQLInputObjectTypeGraphQLInputTypeGraphQLInterfaceTypeGraphQLListGraphQLNamedTypeGraphQLNonNullGraphQLObjectTypeGraphQLScalarTypeGraphQLSchemaGraphQLStringInlineFragmentNodeIntValueNodeListTypeNodeListValueNodeNamedTypeNodeNameNodeNonNullTypeNodeNullValueNodeObjectFieldNodeObjectValueNodeOperationDefinitionNodeOperationTypeSelectionSetNodeStringValueNodeTypeNode	Undefined	ValueNodeVariableDefinitionNodeVariableNodeget_named_typeintrospection_typesis_enum_typeis_input_object_typeis_leaf_typeis_list_typeis_non_null_typeis_wrapping_type	print_ast)inspect   )to_camel_casez^-?(?:0|[1-9][0-9]*)$
serializedreturnc                 C   s  | du s| t u rt S t| tr'dd |  D }tdd |D }t|dS t| trFt| tsFdd | D }tdd |D }t	|dS t| t
rPt| d	S t| tr\tt| d	S t| tryt| ryt| }|d
rt|dd }t|d	S t| trt| d	S tdt|  d)a  Given a serialized value, try our best to produce an AST.

    Anything ressembling an array (instance of Mapping) will be converted
    to an ObjectFieldNode.

    Anything ressembling a list (instance of Iterable - except str)
    will be converted to a ListNode.

    In some cases, a custom scalar can be serialized differently in the query
    than in the variables. In that case, this function will not work.Nc                 s   s     | ]\}}|t |fV  qd S N!ast_from_serialized_value_untyped).0keyvalue rK   ^/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/gql/dsl.py	<genexpr>Y   s
    

z4ast_from_serialized_value_untyped.<locals>.<genexpr>c                 s   *    | ]\}}|rt t|d |dV  qdS rJ   )namerJ   Nr,   r)   rH   
field_namefield_valuerK   rK   rL   rM   ]       
fieldsc                 s   s    | ]}t |V  qd S rE   rF   rH   itemrK   rK   rL   rM   e       c                 s       | ]}|r|V  qd S rE   rK   rH   noderK   rK   rL   rM   f   r[   valuesrP   z.0zCannot convert value to AST: .)r3   r+   
isinstancer   itemstupler-   r   strr'   boolr   intr%   floatr   endswithr   r1   	TypeErrorr@   )rC   field_itemsfield_nodesmaybe_nodesnodesrJ   rK   rK   rL   rG   I   s4   









rG   rJ   type_c           	         s  t tr|jS t|r-tt|}|j}t|}t |t	r+t
dt| d|S du r4t	 S tu rBt
dt| dt|rttt|}|j t trot tso fddD }tdd |D }t|dS t S t|rdu st tsdS tt|}fd	d|j D }td
d |D }t|dS t|r|}t |trt|rt|dS |tu rt|rt |dS t!|dS t"|S t#dt| d)a  
    This is a partial copy paste of the ast_from_value function in
    graphql-core utilities/ast_from_value.py

    Overwrite the if blocks that use recursion and add a new case to return a
    VariableNode when value is a DSLVariable

    Produce a GraphQL Value AST given a Python object.

    Raises a GraphQLError instead of returning None if we receive an Undefined
    of if we receive a Null value for a Non-Null type.
    z(Received Null value for a Non-Null type rb   Nz"Received Undefined value for type c                 3   s    | ]}t | V  qd S rE   )ast_from_valuerY   )	item_typerK   rL   rM      s    z!ast_from_value.<locals>.<genexpr>c                 s   r\   rE   rK   r]   rK   rK   rL   rM      r[   r_   c                 3   s0    | ]\}}| v r|t  | |jfV  qd S rE   )rq   type)rH   rT   fieldrP   rK   rL   rM      s    c                 s   rN   rO   rR   rS   rK   rK   rL   rM      rV   rW   rP   zUnexpected input type: )$rc   DSLVariableset_typeast_variable_namer=   r   r   of_typerq   r+   r   r@   r3   r<   r   r   rf   re   r'   r:   r   r   rX   rd   r-   r;   	serializer9   r   r   _re_integer_stringmatchr%   r1   rG   rk   )	rJ   rp   
inner_type	ast_valuemaybe_value_nodesvalue_nodesrl   rm   rC   rK   )rr   rJ   rL   rq   {   sX   














rq   
operationsDSLExecutableoperations_with_namec                  O   sp   g | dd |  D R }| D ]\}}||_q|D ]}t|ts-tdt| dqtdd |D dS )a  Given arguments instances of :class:`DSLExecutable`
    containing GraphQL operations or fragments,
    generate a Document which can be executed later in a
    gql client or a gql session.

    Similar to the :func:`gql.gql` function but instead of parsing a python
    string to describe the request, we are using operations which have been generated
    dynamically using instances of :class:`DSLField`, generated
    by instances of :class:`DSLType` which themselves originated from
    a :class:`DSLSchema` class.

    :param \*operations: the GraphQL operations and fragments
    :type \*operations: DSLQuery, DSLMutation, DSLSubscription, DSLFragment
    :param \**operations_with_name: the GraphQL operations with an operation name
    :type \**operations_with_name: DSLQuery, DSLMutation, DSLSubscription

    :return: a Document which can be later executed or subscribed by a
        :class:`Client <gql.client.Client>`, by an
        :class:`async session <gql.client.AsyncClientSession>` or by a
        :class:`sync session <gql.client.SyncClientSession>`

    :raises TypeError: if an argument is not an instance of :class:`DSLExecutable`
    :raises AttributeError: if a type has not been provided in a :class:`DSLFragment`
    c                 s   s    | ]}|V  qd S rE   rK   rH   	operationrK   rK   rL   rM      s    zdsl_gql.<locals>.<genexpr>zsOperations should be instances of DSLExecutable (DSLQuery, DSLMutation, DSLSubscription or DSLFragment).
Received: rb   c                 S   s   g | ]}|j qS rK   )executable_astr   rK   rK   rL   
<listcomp>  s    zdsl_gql.<locals>.<listcomp>)definitions)r`   rd   rQ   rc   r   rk   rs   r   )r   r   all_operationsrQ   r   rK   rK   rL   dsl_gql   s$   
r   c                   @   s0   e Zd ZdZdefddZdeddfdd	Zd
S )	DSLSchemazThe DSLSchema is the root of the DSL code.

    Attributes of the DSLSchema class are generated automatically
    with the `__getattr__` dunder method in order to generate
    instances of :class:`DSLType`
    schemac                 C   s&   t |tstdt| || _dS )aG  Initialize the DSLSchema with the given schema.

        :param schema: a GraphQL Schema provided locally or fetched using
                       an introspection query. Usually `client.schema`
        :type schema: GraphQLSchema

        :raises TypeError: if the argument is not an instance of :class:`GraphQLSchema`
        z1DSLSchema needs a schema as parameter. Received: N)rc   r"   rk   rs   _schema)selfr   rK   rK   rL   __init__  s
   


zDSLSchema.__init__rQ   rD   DSLTypec                 C   sR   | j |}|d u rtd| dt|ttfs$td| d|dt|| S )NzType 'z' not found in the schema!zType "z (z`)" is not valid as an attribute of DSLSchema. Only Object types or Interface types are accepted.)r   get_typeAttributeErrorrc   r    r   r   )r   rQ   type_defrK   rK   rL   __getattr__#  s   
zDSLSchema.__getattr__N)__name__
__module____qualname____doc__r"   r   rf   r   rK   rK   rK   rL   r   
  s    r   c                   @   sT   e Zd ZU dZeed< 				dddZed	dd
efddZ					dddZ
dS )DSLSelectoraf  DSLSelector is an abstract class which defines the
    :meth:`select <gql.dsl.DSLSelector.select>` method to select
    children fields in the query.

    Inherited by
    :class:`DSLRootFieldSelector <gql.dsl.DSLRootFieldSelector>`,
    :class:`DSLFieldSelector <gql.dsl.DSLFieldSelector>`
    :class:`DSLFragmentSelector <gql.dsl.DSLFragmentSelector>`
    selection_setrX   DSLSelectablefields_with_aliasDSLSelectableWithAliasc                 O   s,   t dd| _|s
|r| j|i | dS dS ):meta private:rK   )
selectionsN)r0   r   selectr   rX   r   rK   rK   rL   r   @  s   zDSLSelector.__init__rt   rD   c                 C      t d)Nz:Any DSLSelector subclass must have a is_valid_field methodNotImplementedError)r   rt   rK   rK   rL   is_valid_fieldK  s   zDSLSelector.is_valid_fieldc                 O   s   t ||}|D ]}t|tstdt| | |s'td| d|qtdd |D }| j	j
| | j	_
td| d|  dS )	a  Select the fields which should be added.

        :param \*fields: fields or fragments
        :type \*fields: DSLSelectable
        :param \**fields_with_alias: fields or fragments with alias as key
        :type \**fields_with_alias: DSLSelectable

        :raises TypeError: if an argument is not an instance of :class:`DSLSelectable`
        :raises GraphQLError: if an argument is not a valid field
        z7Fields should be instances of DSLSelectable. Received: zInvalid field for z: c                 s   s    | ]}|j V  qd S rE   )	ast_field)rH   rt   rK   rK   rL   rM   s  s    z%DSLSelector.select.<locals>.<genexpr>zAdded fields: z in N)DSLFieldget_aliased_fieldsrc   r   rk   rs   r   r   re   r   r   logdebug)r   rX   r   added_fieldsrt   added_selectionsrK   rK   rL   r   Q  s"   

zDSLSelector.selectNrX   r   r   r   )r   r   r   r   r0   __annotations__r   r   rg   r   r   rK   rK   rK   rL   r   3  s   
 

r   c                   @   sP   e Zd ZU dZded< ee ed< eed< ee	dd Z
				
	dddZdS )r   zInterface for the root elements which can be executed
    in the :func:`dsl_gql <gql.dsl.dsl_gql>` function

    Inherited by
    :class:`DSLOperation <gql.dsl.DSLOperation>` and
    :class:`DSLFragment <gql.dsl.DSLFragment>`
    DSLVariableDefinitionsvariable_definitionsrQ   r   c                 C   r   )8Generates the ast for :func:`dsl_gql <gql.dsl.dsl_gql>`.z<Any DSLExecutable subclass must have executable_ast propertyr   r   rK   rK   rL   r     s   zDSLExecutable.executable_astrX   r   r   r   c                 O   s*   d| _ t | _tj| g|R i | dS )aR  Given arguments of type :class:`DSLSelectable` containing GraphQL requests,
        generate an operation which can be converted to a Document
        using the :func:`dsl_gql <gql.dsl.dsl_gql>`.

        The fields arguments should be either be fragments or
        fields of root GraphQL types
        (Query, Mutation or Subscription) and correspond to the
        operation_type of this operation.

        :param \*fields: root fields or fragments
        :type \*fields: DSLSelectable
        :param \**fields_with_alias: root fields or fragments with alias as key
        :type \**fields_with_alias: DSLSelectable

        :raises TypeError: if an argument is not an instance of :class:`DSLSelectable`
        :raises AssertionError: if an argument is not a field which correspond
                                to the operation type
        N)rQ   r   r   r   r   r   rK   rK   rL   r     s   zDSLExecutable.__init__Nr   )r   r   r   r   r   r	   rf   r0   propertyr   r   r   rK   rK   rK   rL   r   {  s   
 c                   @   s"   e Zd ZdZdddefddZdS )DSLRootFieldSelectora   Class used to define the
    :meth:`is_valid_field <gql.dsl.DSLRootFieldSelector.is_valid_field>` method
    for root fields for the :meth:`select <gql.dsl.DSLSelector.select>` method.

    Inherited by
    :class:`DSLOperation <gql.dsl.DSLOperation>`
    rt   r   rD   c                 C   s   t | tsJ | jj}t |tr$|jdv r|dkS |jdkr"|dkS d	S t |trd|jdus0J |jjj}d}|dkr?|j	}n|dkrG|j
}n|dkrN|j}|du r]td| d d	S |jj|jkS d	S )
a  Check that a field is valid for a root field.

        For operations, the fields arguments should be fields of root GraphQL types
        (Query, Mutation or Subscription) and correspond to the
        operation_type of this operation.

        the :code:`__typename` field can only be added to Query or Mutation.
        the :code:`__schema` and :code:`__type` field can only be added to Query.
        )__schema__typeQUERY
__typenameSUBSCRIPTIONNMUTATIONzRoot type of type z not found in the schema!F)rc   DSLOperationoperation_typerQ   DSLMetaFieldr   dsl_type_dsl_schemar   
query_typemutation_typesubscription_typer   errorparent_type)r   rt   operation_namer   	root_typerK   rK   rL   r     s2   





z#DSLRootFieldSelector.is_valid_fieldN)r   r   r   r   rg   r   rK   rK   rK   rL   r         r   c                   @   s:   e Zd ZU dZeed< edefddZde	fddZ
dS )	r   zInterface for GraphQL operations.

    Inherited by
    :class:`DSLQuery <gql.dsl.DSLQuery>`,
    :class:`DSLMutation <gql.dsl.DSLMutation>` and
    :class:`DSLSubscription <gql.dsl.DSLSubscription>`
    r   rD   c                 C   sB   t dt| j| j| j d| jrdt| jdini ddiS )r   )r   r   r   rQ   rP   
directivesrK   )r.   r/   r   r   r   get_ast_definitionsrQ   r)   r   rK   rK   rL   r     s   zDSLOperation.executable_astc                 C   s   d| j j dS )N<>)	__class__r   r   rK   rK   rL   __repr__     zDSLOperation.__repr__N)r   r   r   r   r/   r   r   r.   r   rf   r   rK   rK   rK   rL   r     s   
 r   c                   @      e Zd ZejZdS )DSLQueryN)r   r   r   r/   r   r   rK   rK   rK   rL   r         
r   c                   @   r   )DSLMutationN)r   r   r   r/   r   r   rK   rK   rK   rL   r     r   r   c                   @   r   )DSLSubscriptionN)r   r   r   r/   r   r   rK   rK   rK   rL   r   	  r   r   c                   @   sT   e Zd ZdZdefddZdedefddZdedd fd	d
Z	de
dd fddZdS )ru   aZ  The DSLVariable represents a single variable defined in a GraphQL operation

    Instances of this class are generated for you automatically as attributes
    of the :class:`DSLVariableDefinitions`

    The type of the variable is set by the :class:`DSLField` instance that receives it
    in the :meth:`args <gql.dsl.DSLField.args>` method.
    rQ   c                 C   s0   || _ d| _tt| j dd| _d| _d| _dS )r   NrP   rQ   )rQ   ast_variable_typer6   r)   rw   default_valuers   r   rQ   rK   rK   rL   r     s
   
zDSLVariable.__init__rp   rD   c                 C   sf   t |r t|trt| |jdS t|tr t| |jdS t|tt	t
fs*J tt|jddS )N)rs   rP   r   )r>   rc   r   r&   to_ast_typerx   r   r*   r!   r   r   r(   r)   rQ   r   rp   rK   rK   rL   r     s   


zDSLVariable.to_ast_typec                 C   s   || _ | || _| S rE   )rs   r   r   r   rK   rK   rL   rv   -  s   zDSLVariable.set_typer   c                 C   s
   || _ | S rE   )r   )r   r   rK   rK   rL   default2  s   zDSLVariable.defaultN)r   r   r   r   rf   r   r   r2   r   rv   r   r   rK   rK   rK   rL   ru     s    	ru   c                   @   s@   e Zd ZdZdd ZdeddfddZdeed	f fd
dZ	dS )r   a  The DSLVariableDefinitions represents variable definitions in a GraphQL operation

    Instances of this class have to be created and set as the `variable_definitions`
    attribute of a DSLOperation instance

    Attributes of the DSLVariableDefinitions class are generated automatically
    with the `__getattr__` dunder method in order to generate
    instances of :class:`DSLVariable`, that can then be used as values
    in the :meth:`args <gql.dsl.DSLField.args>` method.
    c                 C   s
   i | _ dS )r   N)	variablesr   rK   rK   rL   r   C  s   
zDSLVariableDefinitions.__init__rQ   rD   ru   c                 C   s"   || j vrt|| j |< | j | S rE   )r   ru   r   rK   rK   rL   r   G  s   

z"DSLVariableDefinitions.__getattr__.c                 C   s   t dd | j D S )zp
        :meta private:

        Return a list of VariableDefinitionNodes for each variable with a type
        c                 s   sF    | ]}|j d urt|j|j|jd u rd nt|j|j ddV  qd S )NrK   )rs   variabler   r   )rs   r5   r   rw   r   rq   )rH   varrK   rK   rL   rM   R  s    	

	z=DSLVariableDefinitions.get_ast_definitions.<locals>.<genexpr>)re   r   r`   r   rK   rK   rL   r   L  s   	z*DSLVariableDefinitions.get_ast_definitionsN)
r   r   r   r   r   rf   r   r
   r5   r   rK   rK   rK   rL   r   7  s
    r   c                   @   sJ   e Zd ZdZdeeef defddZde	ddfd	d
Z
de	fddZdS )r   a  The DSLType represents a GraphQL type for the DSL code.

    It can be a root type (Query, Mutation or Subscription).
    Or it can be any other object type (Human in the StarWars schema).
    Or it can be an interface type (Character in the StarWars schema).

    Instances of this class are generated for you automatically as attributes
    of the :class:`DSLSchema`

    Attributes of the DSLType class are generated automatically
    with the `__getattr__` dunder method in order to generate
    instances of :class:`DSLField`
    graphql_type
dsl_schemac                 C   s"   || _ || _td| d dS )aU  Initialize the DSLType with the GraphQL type.

        .. warning::
            Don't instantiate this class yourself.
            Use attributes of the :class:`DSLSchema` instead.

        :param graphql_type: the GraphQL type definition from the schema
        :param dsl_schema: reference to the DSLSchema which created this type
        	Creating )N)_typer   r   r   )r   r   r   rK   rK   rL   r   o  s   zDSLType.__init__rQ   rD   r   c                 C   sn   t |}|| jjv r|}| jj| }n|| jjv r"|}| jj| }ntd| d| jj dt|| j|| S )NzField z does not exist in type rb   )rB   r   rX   r   rQ   r   )r   rQ   camel_cased_nameformatted_namert   rK   rK   rL   r     s   zDSLType.__getattr__c                 C   s   d| j j d| jdS Nr    r   )r   r   r   r   rK   rK   rL   r        zDSLType.__repr__N)r   r   r   r   r   r    r   r   r   rf   r   r   rK   rK   rK   rL   r   `  s    

r   c                   @   s\   e Zd ZU dZeeeef ed< e	de
d  deedf ded fdd	Zdefd
dZdS )r   aM  DSLSelectable is an abstract class which indicates that
    the subclasses can be used as arguments of the
    :meth:`select <gql.dsl.DSLSelector.select>` method.

    Inherited by
    :class:`DSLField <gql.dsl.DSLField>`,
    :class:`DSLFragment <gql.dsl.DSLFragment>`
    :class:`DSLInlineFragment <gql.dsl.DSLInlineFragment>`
    r   rX   r   r   rD   )r   .c                 C   s   g | dd |  D R S )z
        :meta private:

        Concatenate all the fields (with or without alias) in a Tuple.

        Set the requested alias for the fields with alias.
        c                 s   s    | ]
\}}| |V  qd S rE   )alias)rH   r   rt   rK   rK   rL   rM     s    z3DSLSelectable.get_aliased_fields.<locals>.<genexpr>)rd   )rX   r   rK   rK   rL   r     s
   z DSLSelectable.get_aliased_fieldsc                 C   s
   t | jS rE   )r?   r   r   rK   rK   rL   __str__  s   
zDSLSelectable.__str__N)r   r   r   r   r   r   r$   r   r   staticmethodr   r   rf   r
   r   r   rK   rK   rK   rL   r     s   
 

r   c                   @   "   e Zd ZdZdedefddZdS )DSLFragmentSelectora7  Class used to define the
    :meth:`is_valid_field <gql.dsl.DSLFragmentSelector.is_valid_field>` method
    for fragments for the :meth:`select <gql.dsl.DSLSelector.select>` method.

    Inherited by
    :class:`DSLFragment <gql.dsl.DSLFragment>`,
    :class:`DSLInlineFragment <gql.dsl.DSLInlineFragment>`
    rt   rD   c                 C   s   t | ttfs	J t |ttfrdS t |tsJ t |tr#|jdkS | j}|dus,J |j|j v r?|j|j j	|j
j	kS dS )Check that a field is valid.Tr   NF)rc   DSLFragmentDSLInlineFragmentr   r   rQ   r   rX   keysrs   rt   )r   rt   fragment_typerK   rK   rL   r     s   

z"DSLFragmentSelector.is_valid_fieldNr   r   r   r   r   rg   r   rK   rK   rK   rL   r     s    	r   c                   @   r   )DSLFieldSelectorzClass used to define the
    :meth:`is_valid_field <gql.dsl.DSLFieldSelector.is_valid_field>` method
    for fields for the :meth:`select <gql.dsl.DSLSelector.select>` method.

    Inherited by
    :class:`DSLField <gql.dsl.DSLField>`,
    rt   rD   c                 C   s   t | tsJ t |ttfrdS t |tsJ t |tr!|jdkS t| jj}t |t	t
fs0dS |j|j v rC|j|j j|jjkS dS )r   Tr   F)rc   r   r   r   r   rQ   r7   rt   rs   r   r    rX   r   )r   rt   r   rK   rK   rL   r     s   

zDSLFieldSelector.is_valid_fieldNr   rK   rK   rK   rL   r     r   r   c                   @   s,   e Zd ZU dZeed< dedd fddZdS )r   zwDSLSelectableWithAlias is an abstract class which indicates that
    the subclasses can be selected with an alias.
    r   r   rD   c                 C   s   t |d| j_| S )a  Set an alias

        .. note::
            You can also pass the alias directly at the
            :meth:`select <gql.dsl.DSLSelector.select>` method.
            :code:`ds.Query.human.select(my_name=ds.Character.name)` is equivalent to:
            :code:`ds.Query.human.select(ds.Character.name.alias("my_name"))`

        :param alias: the alias
        :type alias: str
        :return: itself
        rP   )r)   r   r   )r   r   rK   rK   rL   r     s   zDSLSelectableWithAlias.aliasN)r   r   r   r   r   r   rf   r   rK   rK   rK   rL   r     s   
 r   c                
       s   e Zd ZU dZeeef ed< eed< e	ed< 	dde
deeef de	dee fd	d
Zedd ZdddZdddZde
defddZ						 d fddZde
fddZ  ZS )r   aT  The DSLField represents a GraphQL field for the DSL code.

    Instances of this class are generated for you automatically as attributes
    of the :class:`DSLType`

    If this field contains children fields, then you need to select which ones
    you want in the request using the :meth:`select <gql.dsl.DSLField.select>`
    method.
    r   r   rt   NrQ   r   r   c                 C   sF   || _ || _tt|dddd| _|| _td|  t	|  dS )a  Initialize the DSLField.

        .. warning::
            Don't instantiate this class yourself.
            Use attributes of the :class:`DSLType` instead.

        :param name: the name of the field
        :param parent_type: the GraphQL type definition from the schema of the
                            parent type of the field
        :param field: the GraphQL field definition from the schema
        :param dsl_type: reference of the DSLType instance which created this field
        rP   rK   )rQ   	argumentsr   r   N)
r   rt   r   r)   r   r   r   r   r   r   )r   rQ   r   rt   r   rK   rK   rL   r   "  s   zDSLField.__init__c                 C   s
   | j jjS )r   )r   rQ   rJ   r   rK   rK   rL   rQ   B  s   
zDSLField.namerD   c                 K   s   | j di |S )NrK   argsr   kwargsrK   rK   rL   __call__G  r   zDSLField.__call__c                    sR    j jdusJ  j jt fdd| D   j _td| d d  S )a  Set the arguments of a field

        The arguments are parsed to be stored in the AST of this field.

        .. note::
            You can also call the field directly with your arguments.
            :code:`ds.Query.human(id=1000)` is equivalent to:
            :code:`ds.Query.human.args(id=1000)`

        :param \**kwargs: the arguments (keyword=value)
        :return: itself

        :raises KeyError: if any of the provided arguments does not exist
                          for this field.
        Nc                 3   s4    | ]\}}t t|d t| |jdV  qdS rO   )r   r)   rq   _get_argumentrs   )rH   rQ   rJ   r   rK   rL   rM   ]  s    
z DSLField.args.<locals>.<genexpr>zAdded arguments z
 in field r   )r   r   re   rd   r   r   r   rK   r   rL   r   J  s   zDSLField.argsc                 C   s2   | j j|}|du rtd| d| j  d|S )zMethod used to return the GraphQLArgument definition
        of an argument from its name.

        :raises KeyError: if the provided argument does not exist
                          for this field.
        Nz	Argument z does not exist in rb   )rt   r   getKeyError)r   rQ   argrK   rK   rL   r   i  s   zDSLField._get_argumentrX   r   r   r   c                        t  j|i | | j| j_| S gCalling :meth:`select <gql.dsl.DSLSelector.select>` method with
        corrected typing hints
        superr   r   r   r   r   rK   rL   r   w  s   
zDSLField.selectc                 C   s"   d| j j d| jj d| j dS )Nr   r   z::r   )r   r   r   rQ   r   rK   rK   rL   r     s   "zDSLField.__repr__rE   )rD   r   )rX   r   r   r   rD   r   )r   r   r   r   r   r    r   r   r   r   rf   r	   r   r   r   rQ   r   r   r   r   r   r   __classcell__rK   rK   r  rL   r     s8   
 


 


r   c                
       sl   e Zd ZdZedeeeeeed eeeed de	e
ediddd	Zdef fd
dZ  ZS )r   zDSLMetaField represents a GraphQL meta-field for the DSL code.

    meta-fields are reserved field in the GraphQL type system prefixed with
    "__" two underscores and used for introspection.
    
meta_field__Schema__TyperQ   )rp   r   )r   r   r   rW   c                    sF   z| j j| }W n ty   td| dw t || j | dS )ziInitialize the meta-field.

        :param name: the name between __typename, __schema or __type
        zInvalid meta-field ""N)	meta_typerX   r   r   r  r   )r   rQ   rt   r  rK   rL   r     s   zDSLMetaField.__init__)r   r   r   r   r    r   r#   r   r8   r   r   r  rf   r   r  rK   rK   r  rL   r     s    r   c                       sz   e Zd ZU dZeeef ed< eed< 				ddd	Z						
	 d fddZ
ded
d fddZd
efddZ  ZS )r   zADSLInlineFragment represents an inline fragment for the DSL code.r   r   rX   r   r   r   c                 O   s8   t d|  tdd| _tj| g|R i | dS )a#  Initialize the DSLInlineFragment.

        :param \*fields: new children fields
        :type \*fields: DSLSelectable (DSLField, DSLFragment or DSLInlineFragment)
        :param \**fields_with_alias: new children fields with alias as key
        :type \**fields_with_alias: DSLField
        r   rK   r   N)r   r   r$   r   r   r   r   rK   rK   rL   r     s   zDSLInlineFragment.__init__rD   c                    r   r   r   r   r  rK   rL   r     s   
zDSLInlineFragment.selecttype_conditionc                 C   s$   |j | _ tt| j jdd| j_| S )z2Provides the GraphQL type of this inline fragment.rP   r   )r   r(   r)   rQ   r   r
  r   r
  rK   rK   rL   on  s
   
zDSLInlineFragment.onc                 C   sB   d}z|d| j j 7 }W n	 ty   Y nw d| jj | dS )N z on r   r   )r   rQ   r   r   r   )r   	type_inforK   rK   rL   r     s   zDSLInlineFragment.__repr__r   )rX   r   r   r   rD   r   )r   r   r   r   r   r    r   r   r$   r   r   r   r  rf   r   r  rK   rK   r  rL   r     s$   
 
	r   c                       s   e Zd ZU dZeeeef  ed< e	ed< e
ed< de
fddZede	fdd	Z	
					 d fddZdedd fddZedefddZde
fddZ  ZS )r   zADSLFragment represents a named GraphQL fragment for the DSL code.r   r   rQ   c                 C   s*   t |  || _d| _td|  dS )zkInitialize the DSLFragment.

        :param name: the name of the fragment
        :type name: str
        Nr   )r   r   rQ   r   r   r   r   rK   rK   rL   r     s   

zDSLFragment.__init__rD   c                 C   s   t dd}t| jd|_|S )zast_field property will generate a FragmentSpreadNode with the
        provided name.

        Note: We need to ignore the type because of
        `issue #4125 of mypy <https://github.com/python/mypy/issues/4125>`_.
        rK   r	  rP   )r   r)   rQ   )r   spread_noderK   rK   rL   r     s   
	zDSLFragment.ast_fieldrX   r   r   r   c                    s(   | j du r	tdt j|i | | S )r   N=Missing type condition. Please use .on(type_condition) method)r   r   r  r   r   r  rK   rL   r     s   
zDSLFragment.selectr
  c                 C   s   |j | _ | S )zProvides the GraphQL type of this fragment.

        :param type_condition: the provided type
        :type type_condition: DSLType
        )r   r  rK   rK   rL   r    s   zDSLFragment.onc                 C   s~   | j dusJ | jdu rtd| j }t|dkr	 i }nd|i}tdtt| jj dd| j	d|t| j ddd	S )
zGenerates the ast for :func:`dsl_gql <gql.dsl.dsl_gql>`.

        :raises AttributeError: if a type has not been provided
        Nr  r   r   rP   r   )r
  r   rK   )rQ   r   )
rQ   r   r   r   r   lenr   r(   r)   r   )r   fragment_variable_definitionsvariable_definition_kwargsrK   rK   rL   r   "  s(   



zDSLFragment.executable_astc                 C   s   d| j j d| jdS r   )r   r   rQ   r   rK   rK   rL   r   G  r   zDSLFragment.__repr__)rX   r   r   r   rD   r   )r   r   r   r   r	   r   r    r   r   r   rf   r   r   r   r   r   r  r   r   r   r  rK   rK   r  rL   r     s*   
 
$r   )dr   loggingreabcr   r   mathr   typingr   r   r   r   r	   r
   r   r   graphqlr   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)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   graphql.pyutilsr@   utilsrB   	getLoggerr   r   compilerz   rG   rq   r   r   r   r   r   r   r   r   r   ru   r   r   r   r   r   r   r   r   r   r   rK   rK   rK   rL   <module>   sN    (5

2[
4)H38*)5#!!t#8