44import com .qudini .reactive .logging .Log ;
55import graphql .ExecutionResult ;
66import graphql .GraphQL ;
7+ import graphql .analysis .MaxQueryComplexityInstrumentation ;
78import graphql .analysis .MaxQueryDepthInstrumentation ;
89import graphql .execution .DataFetcherExceptionHandler ;
10+ import graphql .execution .instrumentation .ChainedInstrumentation ;
11+ import graphql .execution .instrumentation .Instrumentation ;
912import graphql .schema .GraphQLSchema ;
1013import lombok .RequiredArgsConstructor ;
1114import org .dataloader .DataLoaderRegistry ;
1619import reactor .core .publisher .Mono ;
1720import reactor .util .context .ContextView ;
1821
22+ import java .util .Arrays ;
1923import java .util .Map ;
2024
2125import static com .qudini .utils .MoreTuples .onBoth ;
@@ -46,7 +50,7 @@ private Mono<Map<String, Object>> execute(ContextView context, GraphQLRequest re
4650 var input = request .toExecutionInput (context , registry );
4751 var graphql = GraphQL
4852 .newGraphQL (schema )
49- .instrumentation (new MaxQueryDepthInstrumentation ( maxDepth ))
53+ .instrumentation (instrumentation ( ))
5054 .defaultDataFetcherExceptionHandler (exceptionHandler )
5155 .build ();
5256 return Log
@@ -60,4 +64,13 @@ private Mono<ServerResponse> respond(Mono<Map<String, Object>> body) {
6064 .body (body , ParameterizedTypeReference .forType (Map .class ));
6165 }
6266
67+ public Instrumentation instrumentation () {
68+ return new ChainedInstrumentation (
69+ Arrays .asList (
70+ new MaxQueryDepthInstrumentation (maxDepth ), // Limit query depth to maxDepth
71+ new MaxQueryComplexityInstrumentation (maxDepth ) // Limit query complexity to maxDepth
72+ )
73+ );
74+ }
75+
6376}
0 commit comments