o
    h                     @   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   b/var/www/html/pro-man-master/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                     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)typehandled)client_options	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-   get_integrationr   r)   r*   r+   r,   r   r.   r
   r/   r    r0   )r   r1   r2   r3   integrationr4   r5   r6   r7   r8   r'   )old_graphql_asyncr   r   _sentry_patched_graphql_asyncG   s2   
 

z5_patch_graphql.<locals>._sentry_patched_graphql_async)graphene_schemagraphql_syncgraphqlr	   r   )r:   r>   r   )r=   r9   r   r   *   s   
r   c                 C   s>   t  r| di }d|d< | S | di dr| d d= | S )NrequestrA   
api_targetdata)r   
setdefaultget)r8   r'   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querymutationsubscription)rH   operation_typezgraphql.operation)rD   category)crumb)opnamezgraphql.documentzgraphql.operation.namezgraphql.operation.type)rF   r   GRAPHQL_QUERYstrip
startswithGRAPHQL_MUTATIONGRAPHQL_SUBSCRIPTIONr(   add_breadcrumbget_current_scopespanstart_child
start_spanset_datafinish)r   r1   r3   rH   rL   rO   r4   _graphql_spanr   r   r   r,   r   s6   

r,   )'
contextlibr   r(   sentry_sdk.constsr   sentry_sdk.integrationsr   r   r   sentry_sdk.scoper   sentry_sdk.utilsr   r	   r
   r   graphene.typesr   r?   ImportErrortypingr   collections.abcr   r   r   r   graphene.language.sourcer   graphql.executionr   graphql.typer   sentry_sdk._typesr   r   r   r+   r,   r   r   r   r   <module>   s0    <