@@ -47,7 +47,14 @@ class GraphQLQueryPurifier {
4747 if ( allowedQuery ) {
4848 // Use mergeQueries with the specific allowed query
4949 const filteredQuery = ( 0 , merge_1 . mergeQueries ) ( req . body . query , allowedQuery , this . debug ) ;
50- // Existing code...
50+ if ( ! filteredQuery . trim ( ) ) {
51+ console . warn ( `Query was blocked due to security rules: ${ req . body . query } ` ) ;
52+ req . body . query = '{ __typename }' ;
53+ delete req . body . operationName ;
54+ }
55+ else {
56+ req . body . query = filteredQuery ;
57+ }
5158 }
5259 else {
5360 console . warn ( `Query was blocked: ${ req . body . query } ` ) ;
@@ -78,6 +85,10 @@ class GraphQLQueryPurifier {
7885 */
7986 loadQueries ( ) {
8087 const files = glob_1 . default . sync ( `${ this . gqlPath } /**/*.gql` . replace ( / \\ / g, '/' ) ) ;
88+ if ( ! files || files . length === 0 ) {
89+ console . warn ( `No GraphQL files found in path: ${ this . gqlPath } ` ) ;
90+ return ;
91+ }
8192 this . queryMap = { } ;
8293 files . forEach ( ( file ) => {
8394 const content = fs_1 . default . readFileSync ( file , 'utf8' ) . trim ( ) ;
@@ -92,7 +103,12 @@ class GraphQLQueryPurifier {
92103 const firstField = operationDefinition . selectionSet . selections . find ( ( sel ) => sel . kind === 'Field' ) ;
93104 const firstFieldName = firstField ? firstField . name . value : '' ;
94105 const key = `${ operationName } .${ firstFieldName } ` . trim ( ) ;
95- this . queryMap [ key ] = content ;
106+ if ( this . queryMap [ key ] ) {
107+ throw new Error ( `Duplicate operation name detected: ${ key } . File: ${ file } ` ) ;
108+ }
109+ else {
110+ this . queryMap [ key ] = content ;
111+ }
96112 }
97113 } ) ;
98114 }
0 commit comments