o
    tBh                     @   s   d dl 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 d dlmZ 	ddedee defdd	Zd
ededefddZ	ddededeeef dee deeef f
ddZdS )    )AnyDictOptional)DocumentNodeGraphQLEnumTypeGraphQLErrorGraphQLInputObjectTypeGraphQLListGraphQLNonNullGraphQLScalarTypeGraphQLSchemaGraphQLTypeGraphQLWrappingTypeOperationDefinitionNodetype_from_ast)inspectNdocumentoperation_namereturnc                 C   sr   d}| j D ]}t|tr$|du r|rtd|}q|jr$|jj|kr$|}q|s7|dur3td| dtd|S )zReturns the operation which should be executed in the document.

    Raises a GraphQLError if a single operation cannot be retrieved.
    NzBMust provide operation name if query contains multiple operations.zUnknown operation named 'z'.zMust provide an operation.)definitions
isinstancer   r   namevalue)r   r   	operation
definition r   ~/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/gql/utilities/serialize_variable_values.py_get_document_operation   s"   

r   type_r   c                    s   du rt | trtdt|  ddS t | tr6| j t | tr't S t | tr5 fddD S nt | tt	frB| 
S t | trSfdd| j D S tdt|  d	)
a;  Given a GraphQL type and a Python value, return the serialized value.

    This method will serialize the value recursively, entering into
    lists and dicts.

    Can be used to serialize Enums and/or Custom Scalars in variable values.

    :param type_: the GraphQL type
    :param value: the provided value
    NzType z Cannot be None.c                    s   g | ]}t  |qS r   )serialize_value).0v)
inner_typer   r   
<listcomp>O   s    z#serialize_value.<locals>.<listcomp>c                    s*   i | ]\}}| v r|t |j | qS r   )r   type)r    
field_namefield)r   r   r   
<dictcomp>U   s
    z#serialize_value.<locals>.<dictcomp>z)Impossible to serialize value with type: .)r   r
   r   r   r   of_typer   r	   r   r   	serializer   fieldsitems)r   r   r   )r"   r   r   r   5   s$   







r   schemavariable_valuesc           
      C   s`   i }t ||d}|jD ]"}|jjj}t| |j}||v r-|dus"J || }	t||	||< q|S )a  Given a GraphQL document and a schema, serialize the Dictionary of
    variable values.

    Useful to serialize Enums and/or Custom Scalars in variable values.

    :param schema: the GraphQL schema
    :param document: the document representing the query sent to the backend
    :param variable_values: the dictionnary of variable values which needs
        to be serialized.
    :param operation_name: the optional operation_name for the query.
    )r   N)r   variable_definitionsvariabler   r   r   r$   r   )
r-   r   r.   r   parsed_variable_valuesr   var_def_nodevar_namevar_type	var_valuer   r   r   serialize_variable_values^   s   

r6   )N)typingr   r   r   graphqlr   r   r   r   r	   r
   r   r   r   r   r   r   graphql.pyutilsr   strr   r   r6   r   r   r   r   <module>   s0    8
!-

