o
    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dZ$d$ddZ%e								 d%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dZdS )GrapheneIntegrationgraphenereturnNc                  C   s   t d} tt|  t  d S )Nr   )r   r   r   _patch_graphql)version r   ]/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/sentry_sdk/integrations/graphene.py
setup_once!   s   

zGrapheneIntegration.setup_oncer   N)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r      s    r   r   c                     sj   t jt j tt											dfd
d} 											d fdd}| t _|t _d S )Nr   r   sourceUnion[str, Source]argsr   kwargsr   r   c           
         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   r$   r&   r'   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.   r3   get_integrationr   r/   r0   r1   r2   r   r4   r
   r5   r"   r6   )r   r$   r&   r'   integrationr7   r8   r9   r:   r;   r-   )old_graphql_asyncr   r   _sentry_patched_graphql_asyncI   s2   
 

z5_patch_graphql.<locals>._sentry_patched_graphql_async)
r   r   r$   r%   r&   r   r'   r   r   r   )graphene_schemagraphql_syncgraphqlr	   r   )r=   rA   r   )r@   r<   r   r   )   s6   
r   r;   r   r-   Dict[str, Any]c                 C   s>   t  r| di }d|d< | S | di dr| d d= | S )NrequestrD   
api_targetdata)r   
setdefaultget)r;   r-   request_infor   r   r   r1   l   s   
r1   r   r   r$   r%   r'   Generator[None, None, None]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)rM   operation_typezgraphql.operation)rH   category)crumb)opnamezgraphql.documentzgraphql.operation.namezgraphql.operation.type)rJ   r   GRAPHQL_QUERYstrip
startswithGRAPHQL_MUTATIONGRAPHQL_SUBSCRIPTIONr.   add_breadcrumbget_current_scopespanstart_child
start_spanset_datafinish)r   r$   r'   rM   rQ   rT   r7   _graphql_spanr   r   r   r2   w   s6   

r2   r   )r;   r   r-   rE   r   r   )r   r   r$   r%   r'   rE   r   rL   )'
contextlibr   r.   sentry_sdk.constsr   sentry_sdk.integrationsr   r   r   sentry_sdk.scoper   sentry_sdk.utilsr   r	   r
   r   graphene.typesr   rB   ImportErrortypingr   collections.abcr   r   r   r   graphene.language.sourcer   graphql.executionr   graphql.typer   sentry_sdk._typesr   r   r   r1   r2   r   r   r   r   <module>   s@    

C