@@ -65,11 +65,13 @@ function _updateSpanWithGraphQLData(client: Client, options: GraphQLClientOption
6565 const payload = getRequestPayloadXhrOrFetch ( hint ) ;
6666
6767 if ( isTracedGraphqlEndpoint && payload ) {
68- const graphqlBody = getGraphQLRequestPayload ( payload ) as GraphQLRequestPayload ;
69- const operationInfo = _getGraphQLOperation ( graphqlBody ) ;
68+ const graphqlBody = getGraphQLRequestPayload ( payload ) ;
7069
71- span . updateName ( `${ httpMethod } ${ httpUrl } (${ operationInfo } )` ) ;
72- span . setAttribute ( 'graphql.document' , payload ) ;
70+ if ( graphqlBody ) {
71+ const operationInfo = _getGraphQLOperation ( graphqlBody ) ;
72+ span . updateName ( `${ httpMethod } ${ httpUrl } (${ operationInfo } )` ) ;
73+ span . setAttribute ( 'graphql.document' , payload ) ;
74+ }
7375 }
7476 } ) ;
7577}
@@ -93,8 +95,8 @@ function _updateBreadcrumbWithGraphQLData(client: Client, options: GraphQLClient
9395 const graphqlBody = getGraphQLRequestPayload ( payload ) ;
9496
9597 if ( ! data . graphql && graphqlBody ) {
96- const operationInfo = _getGraphQLOperation ( graphqlBody as GraphQLRequestPayload ) ;
97- data [ 'graphql.document' ] = ( graphqlBody as GraphQLRequestPayload ) . query ;
98+ const operationInfo = _getGraphQLOperation ( graphqlBody ) ;
99+ data [ 'graphql.document' ] = graphqlBody . query ;
98100 data [ 'graphql.operation' ] = operationInfo ;
99101 }
100102 }
@@ -182,14 +184,13 @@ export function parseGraphQLQuery(query: string): GraphQLOperation {
182184 * @param payload - A valid JSON string
183185 * @returns A POJO or undefined
184186 */
185- export function getGraphQLRequestPayload ( payload : string ) : unknown | undefined {
187+ export function getGraphQLRequestPayload ( payload : string ) : GraphQLRequestPayload | undefined {
186188 let graphqlBody = undefined ;
187189 try {
188- const requestBody = JSON . parse ( payload ) ;
190+ const requestBody = JSON . parse ( payload ) satisfies GraphQLRequestPayload ;
189191
190192 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
191193 const isGraphQLRequest = ! ! requestBody [ 'query' ] ;
192-
193194 if ( isGraphQLRequest ) {
194195 graphqlBody = requestBody ;
195196 }
0 commit comments