o
    0 i                     @   s  d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZmZmZmZ zd dlmZ W n ey?   edw d d	lmZ erpd d
lmZ d dlmZmZmZ d dl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%edd Z&dS )    )contextmanagerN)OP)_check_minimum_versionDidNotEnableIntegration)should_send_default_pii)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionpackage_version)schemazgraphene is not installed)TYPE_CHECKING)	Generator)AnyDictUnion)Source)ExecutionResult)GraphQLSchema)Eventc                   @   s   e Zd ZdZedd ZdS )GrapheneIntegrationgraphenec                  C   s   t d} tt|  t  d S )Nr   )r   r   r   _patch_graphql)version r   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/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                     s>   t jt j ttfdd}  fdd}| t _|t _d S )Nc           
         s   t  }|t t| ||  | |g|R i |}W d    n1 s&w   Y  t * t  }|jp7g D ]}t||j	t
jddd\}}	t j||	d q8W d    |S 1 s[w   Y  |S NF)typeZhandled)Zclient_optionsZ	mechanism)hint)
sentry_sdkget_isolation_scopeadd_event_processor_event_processorgraphql_spanr   
get_clienterrorsr
   optionsr   r    capture_event)
r   sourceargskwargsscoperesultclienterroreventr$   )old_graphql_syncr   r   _sentry_patched_graphql_sync/   s*   


z4_patch_graphql.<locals>._sentry_patched_graphql_syncc                    s   t  t}|d u r | |g|R i |I d H S t  }|t t| ||  | |g|R i |I d H }W d    n1 sDw   Y  t * t  }|j	pUg D ]}t
||jtjddd\}	}
t j|	|
d qVW d    |S 1 syw   Y  |S r"   )r%   r*   Zget_integrationr   r&   r'   r(   r)   r   r+   r
   r,   r    r-   )r   r.   r/   r0   Zintegrationr1   r2   r3   r4   r5   r$   )old_graphql_asyncr   r   _sentry_patched_graphql_asyncG   s2   
 

z5_patch_graphql.<locals>._sentry_patched_graphql_async)graphene_schemaZgraphql_syncgraphqlr	   r   )r7   r9   r   )r8   r6   r   r   *   s   
r   c                 C   s>   t  r| di }d|d< | S | di dr| d d= | S )Nrequestr;   Z
api_targetdata)r   
setdefaultget)r5   r$   Zrequest_infor   r   r   r(   f   s   
r(   c                 c   s    | d}d}tj}| drd}tj}n| dr$d}tj}tj||dddd t	 }|j
r@|j
j||d	}ntj||d	}|d
| |d| |d| z
d V  W |  d S |  w )Noperation_namequeryZmutationZsubscription)r@   operation_typezgraphql.operation)r=   category)Zcrumb)opnamezgraphql.documentzgraphql.operation.namezgraphql.operation.type)r?   r   ZGRAPHQL_QUERYstrip
startswithZGRAPHQL_MUTATIONZGRAPHQL_SUBSCRIPTIONr%   Zadd_breadcrumbZget_current_scopespanZstart_childZ
start_spanset_datafinish)r   r.   r0   r@   rB   rD   r1   Z_graphql_spanr   r   r   r)   r   s6   

r)   )'
contextlibr   r%   Zsentry_sdk.constsr   Zsentry_sdk.integrationsr   r   r   Zsentry_sdk.scoper   Zsentry_sdk.utilsr   r	   r
   r   Zgraphene.typesr   r:   ImportErrortypingr   collections.abcr   r   r   r   Zgraphene.language.sourcer   Zgraphql.executionr   Zgraphql.typer   Zsentry_sdk._typesr   r   r   r(   r)   r   r   r   r   <module>   s0    <