File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
packages/rum-core/src/domain/resource Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,25 @@ describe('GraphQL detection and metadata extraction', () => {
142142 const result = extractGraphQlRequestMetadata ( requestBody , true )
143143 expect ( result ) . toBeUndefined ( )
144144 } )
145+
146+ it ( 'should extract query operation name and variables for persisted queries' , ( ) => {
147+ const requestBody = JSON . stringify ( {
148+ extensions : {
149+ persistedQuery : {
150+ sha256Hash : 'somehashvalue' ,
151+ } ,
152+ } ,
153+ operationName : 'GetUser' ,
154+ variables : { id : '123' } ,
155+ } )
156+
157+ const result = extractGraphQlRequestMetadata ( requestBody , true )
158+
159+ expect ( result ) . toEqual ( {
160+ operationName : 'GetUser' ,
161+ variables : '{"id":"123"}' ,
162+ } )
163+ } )
145164 } )
146165
147166 describe ( 'request payload truncation' , ( ) => {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export interface GraphQlError {
1515}
1616
1717export interface GraphQlMetadata {
18- operationType : 'query' | 'mutation' | 'subscription'
18+ operationType ? : 'query' | 'mutation' | 'subscription'
1919 operationName ?: string
2020 variables ?: string
2121 payload ?: string
@@ -88,7 +88,12 @@ export function extractGraphQlRequestMetadata(
8888 return
8989 }
9090
91- let graphqlBody : { query ?: string ; operationName ?: string ; variables ?: unknown }
91+ let graphqlBody : {
92+ query ?: string
93+ operationName ?: string
94+ variables ?: unknown
95+ extensions ?: { persistedQuery ?: unknown }
96+ }
9297
9398 try {
9499 graphqlBody = JSON . parse ( requestBody )
@@ -97,6 +102,13 @@ export function extractGraphQlRequestMetadata(
97102 return
98103 }
99104
105+ if ( graphqlBody && graphqlBody . extensions ?. persistedQuery ) {
106+ return {
107+ operationName : graphqlBody . operationName ,
108+ variables : graphqlBody . variables ? JSON . stringify ( graphqlBody . variables ) : undefined ,
109+ }
110+ }
111+
100112 if ( ! graphqlBody || ! graphqlBody . query ) {
101113 return
102114 }
You can’t perform that action at this time.
0 commit comments