
org.opentripplanner.apis.transmodel.MaxFieldsInResultInstrumentation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
The newest version!
package org.opentripplanner.apis.transmodel;
import static graphql.execution.instrumentation.SimpleInstrumentationContext.noOp;
import graphql.ExecutionResult;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.InstrumentationContext;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters;
import jakarta.validation.constraints.NotNull;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import org.opentripplanner.framework.application.OTPRequestTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A GraphQL instrumentation that aborts the execution if the number of fetched fields exceeds
* a configurable limit.
* The instrumentation also periodically checks the OTP request interruption status while the
* query is being processed, giving the possibility to control the request runtime complexity
* both in terms of result size and execution time.
*/
public class MaxFieldsInResultInstrumentation implements Instrumentation {
private static final Logger LOG = LoggerFactory.getLogger(MaxFieldsInResultInstrumentation.class);
/**
* The maximum number of fields that can be present in the GraphQL result.
*/
private final int maxFieldFetch;
private final AtomicLong fieldFetchCounter = new AtomicLong();
public MaxFieldsInResultInstrumentation(int maxFieldFetch) {
this.maxFieldFetch = maxFieldFetch;
}
@Override
public InstrumentationContext
© 2015 - 2025 Weber Informatics LLC | Privacy Policy