o
    tBhX	                  
   @   sr   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ededeeeef ee f defd	d
ZdS )    )Enum)AnyDictMappingTypeUnioncast)GraphQLEnumTypeGraphQLSchemaFschemanamevaluesuse_enum_valuesc              	   C   s   t |tr"t|tr"ttt |}|rdd |D }ndd |D }t |ts0tdt| | |}|du rAt	d| dt |t
sRtd| d	t| |j D ]\}}z|| |_W qW t	yq   t	d
| dw d|jv r}|jd= dS dS )a  Update in the schema the GraphQLEnumType corresponding to the given name.

    Example::

        from enum import Enum

        class Color(Enum):
            RED = 0
            GREEN = 1
            BLUE = 2

        update_schema_enum(schema, 'Color', Color)

    :param schema: a GraphQL Schema already containing the GraphQLEnumType type.
    :param name: the name of the enum in the GraphQL schema
    :param values: Either a Python Enum or a dict of values. The keys of the provided
        values should correspond to the keys of the existing enum in the schema.
    :param use_enum_values: By default, we configure the GraphQLEnumType to serialize
        to enum instances (ie: .parse_value() returns Color.RED).
        If use_enum_values is set to True, then .parse_value() returns 0.
        use_enum_values=True is the defaut behaviour when passing an Enum
        to a GraphQLEnumType.
    c                 S   s   i | ]}|j |jqS  )r   value.0enumr   r   w/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/gql/utilities/update_schema_enum.py
<dictcomp>*   s    z&update_schema_enum.<locals>.<dictcomp>c                 S   s   i | ]}|j |qS r   )r   r   r   r   r   r   ,   s    zInvalid type for enum values: NzEnum z not found in schema!z
The type "z$" is not a GraphQLEnumType, it is a z
Enum key "z" not found in provided values!_value_lookup)
isinstancetype
issubclassr   r   r   r   	TypeErrorget_typeKeyErrorr	   r   itemsr   __dict__)r   r   r   r   schema_enum	enum_name
enum_valuer   r   r   update_schema_enum   s0   





r"   N)F)r   r   typingr   r   r   r   r   r   graphqlr	   r
   strboolr"   r   r   r   r   <module>   s     