11import { SENTRY_XHR_DATA_KEY } from '@sentry-internal/browser-utils' ;
2- import { FetchHint , getBodyString , XhrHint } from '@sentry-internal/replay' ;
2+ import { getBodyString } from '@sentry-internal/replay' ;
3+ import type { FetchHint , XhrHint } from '@sentry-internal/replay' ;
34import {
45 SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD ,
56 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
@@ -22,6 +23,11 @@ interface GraphQLRequestPayload {
2223 extensions ?: Record < string , unknown > ;
2324}
2425
26+ interface GraphQLOperation {
27+ operationType : string | undefined ;
28+ operationName : string | undefined ;
29+ }
30+
2531const INTEGRATION_NAME = 'GraphQLClient' ;
2632
2733const _graphqlClientIntegration = ( ( options : GraphQLClientOptions ) => {
@@ -65,7 +71,6 @@ function _updateSpanWithGraphQLData(client: Client, options: GraphQLClientOption
6571 span . updateName ( `${ httpMethod } ${ httpUrl } (${ operationInfo } )` ) ;
6672 span . setAttribute ( 'graphql.document' , payload ) ;
6773 }
68-
6974 } ) ;
7075}
7176
@@ -92,11 +97,6 @@ function _updateBreadcrumbWithGraphQLData(client: Client, options: GraphQLClient
9297 data [ 'graphql.document' ] = ( graphqlBody as GraphQLRequestPayload ) . query ;
9398 data [ 'graphql.operation' ] = operationInfo ;
9499 }
95-
96- // The body prop attached to HandlerDataFetch for the span should be removed.
97- if ( isFetch && data . body ) {
98- delete data . body ;
99- }
100100 }
101101 }
102102 } ) ;
@@ -121,7 +121,7 @@ function _getGraphQLOperation(requestBody: GraphQLRequestPayload): string {
121121 */
122122function _getRequestPayloadXhrOrFetch ( hint : XhrHint | FetchHint ) : string | undefined {
123123 const isXhr = 'xhr' in hint ;
124- const isFetch = ! isXhr
124+ const isFetch = ! isXhr ;
125125
126126 let body : string | undefined ;
127127
@@ -136,6 +136,7 @@ function _getRequestPayloadXhrOrFetch(hint: XhrHint | FetchHint): string | undef
136136 return body ;
137137}
138138
139+ // Duplicate from deprecated @sentry -utils/src/instrument/fetch.ts
139140function hasProp < T extends string > ( obj : unknown , prop : T ) : obj is Record < string , string > {
140141 return ! ! obj && typeof obj === 'object' && ! ! ( obj as Record < string , string > ) [ prop ] ;
141142}
@@ -154,13 +155,9 @@ export function parseFetchPayload(fetchArgs: unknown[]): string | undefined {
154155 return hasProp ( arg , 'body' ) ? String ( arg . body ) : undefined ;
155156}
156157
157- interface GraphQLOperation {
158- operationType : string | undefined ;
159- operationName : string | undefined ;
160- }
161-
162158/**
163159 * Extract the name and type of the operation from the GraphQL query.
160+ * Exported for tests only.
164161 * @param query
165162 */
166163export function parseGraphQLQuery ( query : string ) : GraphQLOperation {
0 commit comments