o
    h                     @   s   d dl mZmZ d dlmZmZ d dlmZmZm	Z	 d dl
mZ zd dlmZ W n ey3   edw erRd dlmZmZmZ d dlmZ d d	lmZ d d
lmZ G dd deZdd Zdd ZdS )    )Hub_should_send_default_pii)DidNotEnableIntegration)capture_internal_exceptionsevent_from_exceptionpackage_version)TYPE_CHECKING)schemazgraphene is not installed)AnyDictUnion)Source)ExecutionResult)GraphQLSchemac                   @   s   e Zd ZdZedd ZdS )GrapheneIntegrationgraphenec                  C   s2   t d} | d u rtd| dk rtdt  d S )Nr   zUnparsable graphene version.)   r   zgraphene 3.3 or newer required.)r   r   _patch_graphql)version r   c/var/www/html/aiguide_backend/venv/lib/python3.10/site-packages/sentry_sdk/integrations/graphene.py
setup_once   s   
zGrapheneIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r      s    r   c                     s4   t jt j fdd}  fdd}| t _|t _d S )Nc                    s   t j}|t}|d u r | |g|R i |S | }|t W d    n1 s,w   Y   | |g|R i |}t , |jpEg D ]}t	||j
rQ|j
jnd |jddd\}	}
|j|	|
d qFW d    |S 1 sow   Y  |S NF)typehandled)client_options	mechanism)hintr   currentget_integrationr   configure_scopeadd_event_processor_event_processorr   errorsr   clientoptionsr   capture_eventr
   sourceargskwargshubintegrationscoperesulterroreventr#   )old_graphql_syncr   r   _sentry_patched_graphql_sync.   s.   



z4_patch_graphql.<locals>._sentry_patched_graphql_syncc                    s   t j}|t}|d u r | |g|R i |I d H S | }|t W d    n1 s0w   Y   | |g|R i |I d H }t , |jpLg D ]}t	||j
rX|j
jnd |jddd\}	}
|j|	|
d qMW d    |S 1 svw   Y  |S r   r$   r.   )old_graphql_asyncr   r   _sentry_patched_graphql_asyncH   s0   



z5_patch_graphql.<locals>._sentry_patched_graphql_async)graphene_schemagraphql_syncgraphql)r9   r;   r   )r:   r8   r   r   )   s   
r   c                 C   s>   t  r| di }d|d< | S | di dr| d d= | S )Nrequestr>   
api_targetdata)r   
setdefaultget)r7   r#   request_infor   r   r   r)   f   s   
r)   N)sentry_sdk.hubr   r   sentry_sdk.integrationsr   r   sentry_sdk.utilsr   r   r   sentry_sdk._typesr	   graphene.typesr
   r<   ImportErrortypingr   r   r   graphene.language.sourcer   graphql.executionr   graphql.typer   r   r   r)   r   r   r   r   <module>   s"    =