Skip to content

Commit

Permalink
updated Introspection taken care
Browse files Browse the repository at this point in the history
Signed-off-by: raovishal <Vishal.Rao@verint.com>
  • Loading branch information
Vishal-Rao-SU committed Aug 6, 2024
1 parent 0f376d5 commit b045eca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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 Expand Up @@ -98,5 +99,4 @@ public RouterFunction<ServerResponse> graphqlRouter(GraphQLHandler graphqlHandle
graphqlHandler::postJson
);
}

}
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
)
);
}

}

0 comments on commit b045eca

Please sign in to comment.