Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import graphql.schema.idl.TypeRuntimeWiring;
import graphql.schema.visibility.NoIntrospectionGraphqlFieldVisibility;
import lombok.SneakyThrows;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -68,7 +69,7 @@ public TypeDefinitionRegistry graphqlRegistry(@Value("classpath:schema.graphql")
@Bean
@ConditionalOnMissingBean
public RuntimeWiring graphqlWiring(Gom gom, Collection<Scalar<?, ?, ?>> scalars, Collection<TypeRuntimeWiring> wirings) {
var wiring = RuntimeWiring.newRuntimeWiring();
var wiring = RuntimeWiring.newRuntimeWiring().fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY);
scalars.stream().map(Scalar::build).forEach(wiring::scalar);
wirings.forEach(wiring::type);
gom.decorateRuntimeWiringBuilder(wiring);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import com.qudini.reactive.logging.Log;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.analysis.MaxQueryComplexityInstrumentation;
import graphql.analysis.MaxQueryDepthInstrumentation;
import graphql.execution.DataFetcherExceptionHandler;
import graphql.execution.instrumentation.ChainedInstrumentation;
import graphql.execution.instrumentation.Instrumentation;
import graphql.schema.GraphQLSchema;
import lombok.RequiredArgsConstructor;
import org.dataloader.DataLoaderRegistry;
Expand All @@ -16,6 +19,7 @@
import reactor.core.publisher.Mono;
import reactor.util.context.ContextView;

import java.util.Arrays;
import java.util.Map;

import static com.qudini.utils.MoreTuples.onBoth;
Expand Down Expand Up @@ -46,7 +50,7 @@ private Mono<Map<String, Object>> execute(ContextView context, GraphQLRequest re
var input = request.toExecutionInput(context, registry);
var graphql = GraphQL
.newGraphQL(schema)
.instrumentation(new MaxQueryDepthInstrumentation(maxDepth))
.instrumentation(instrumentation())
.defaultDataFetcherExceptionHandler(exceptionHandler)
.build();
return Log
Expand All @@ -60,4 +64,13 @@ private Mono<ServerResponse> respond(Mono<Map<String, Object>> body) {
.body(body, ParameterizedTypeReference.forType(Map.class));
}

public Instrumentation instrumentation() {
return new ChainedInstrumentation(
Arrays.asList(
new MaxQueryDepthInstrumentation(maxDepth), // Limit query depth to maxDepth
new MaxQueryComplexityInstrumentation(maxDepth) // Limit query complexity to maxDepth
)
);
}

}