U 췀g9@sddlmZddlZddlmZddlmZmZddlm Z ddl m Z m Z m Z mZzddlmZWnek redYnXdd lmZerdd lmZdd lmZmZmZdd lmZdd lmZddlmZddl m!Z!GdddeZ"ddZ#ddZ$eddZ%dS))contextmanagerN)OP) DidNotEnable Integration)should_send_default_pii)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionpackage_version)schemazgraphene is not installed) TYPE_CHECKING) Generator)AnyDictUnion)Source)ExecutionResult) GraphQLSchema)Eventc@seZdZdZeddZdS)GrapheneIntegrationgraphenecCs2td}|dkrtd|dkr(tdtdS)NrzUnparsable graphene version.)rzgraphene 3.3 or newer required.)r r_patch_graphql)versionrN/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/graphene.py setup_once!s zGrapheneIntegration.setup_onceN)__name__ __module__ __qualname__ identifier staticmethodrrrrrrsrcs>tjtjttfdd}fdd}|t_|t_dS)Nc st}|tt|||||f||}W5QRXtHt}|jpTgD].}t||j t j ddd\}} tj || dqVW5QRX|SNF)typeZhandled)Zclient_optionsZ mechanism)hint) sentry_sdkget_isolation_scopeadd_event_processor_event_processor graphql_spanr get_clienterrorsr optionsrr capture_event) r sourceargskwargsscoperesultclienterroreventr$)old_graphql_syncrr_sentry_patched_graphql_sync4s   z4_patch_graphql.._sentry_patched_graphql_syncc stt}|dkr.||f||IdHSt}|tt|||||f||IdH}W5QRXtHt}|j pgD].}t ||j tj ddd\} } tj | | dqW5QRX|Sr")r%r*Zget_integrationrr&r'r(r)rr+r r,r r-) r r.r/r0Z integrationr1r2r3r4r5r$)old_graphql_asyncrr_sentry_patched_graphql_asyncLs& " z5_patch_graphql.._sentry_patched_graphql_async)graphene_schemaZ graphql_syncgraphqlrr)r7r9r)r8r6rr/s rcCs<tr|di}d|d<n|didr8|dd=|S)Nrequestr;Z api_targetdata)r setdefaultget)r5r$Z request_inforrrr(ks    r(ccs|d}d}tj}|dr.d}tj}n|drFd}tj}tj||ddddt }|j r~|j j ||d }ntj ||d }| d || d || d |z dVW5|XdS) Noperation_namequeryZmutationZ subscription)r@operation_typezgraphql.operation)r=category)Zcrumb)opnamezgraphql.documentzgraphql.operation.namezgraphql.operation.type)r?rZ GRAPHQL_QUERYstrip startswithZGRAPHQL_MUTATIONZGRAPHQL_SUBSCRIPTIONr%Zadd_breadcrumbZget_current_scopespanZ start_childZ start_spanset_datafinish)r r.r0r@rBrDr1Z _graphql_spanrrrr)ws4      r))& contextlibrr%Zsentry_sdk.constsrZsentry_sdk.integrationsrrZsentry_sdk.scoperZsentry_sdk.utilsrrr r Zgraphene.typesr r: ImportErrortypingr collections.abcr rrrZgraphene.language.sourcerZgraphql.executionrZ graphql.typerZsentry_sdk._typesrrrr(r)rrrrs,         <