Class CacheControlInstrumentation
java.lang.Object
graphql.execution.instrumentation.SimplePerformantInstrumentation
com.apollographql.federation.graphqljava.caching.CacheControlInstrumentation
- All Implemented Interfaces:
graphql.execution.instrumentation.Instrumentation
public class CacheControlInstrumentation
extends graphql.execution.instrumentation.SimplePerformantInstrumentation
A GraphQL Java Instrumentation that computes a max age for an operation based on @cacheControl
directives.
By default, this instrumentation will only set the `Cache-Control` `max-age` value IF positive int value is provided. If you would rather want to return explicit `max-age=0` values, you need to explicitly opt-in to this behavior by specifying `allowZeroMaxAge=true` constructor value.
You can retrieve the "max-age=..." header value with a GraphQLContext:
String cacheControlHeader = CacheControlInstrumentation.cacheControlContext(context);
See @cacheControl documentation and the original Apollo Server plugin-response-cache implementation.
-
Field Summary
Fields inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
INSTANCE -
Constructor Summary
ConstructorsConstructorDescriptionCacheControlInstrumentation(int defaultMaxAge) CacheControlInstrumentation(int defaultMaxAge, boolean allowZeroMaxAge) -
Method Summary
Modifier and TypeMethodDescriptiongraphql.execution.instrumentation.InstrumentationContext<graphql.ExecutionResult>beginExecution(graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters parameters, graphql.execution.instrumentation.InstrumentationState state) @Nullable graphql.execution.instrumentation.InstrumentationContext<Object>beginFieldExecution(graphql.execution.instrumentation.parameters.InstrumentationFieldParameters parameters, graphql.execution.instrumentation.InstrumentationState state) static @Nullable StringcacheControlHeaderFromGraphQLContext(graphql.GraphQLContext context) graphql.execution.instrumentation.InstrumentationStatecreateState(graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters parameters) Methods inherited from class graphql.execution.instrumentation.SimplePerformantInstrumentation
beginExecuteObject, beginExecuteOperation, beginExecutionStrategy, beginFieldCompletion, beginFieldFetch, beginFieldListCompletion, beginParse, beginSubscribedFieldEvent, beginValidation, createStateAsync, instrumentDataFetcher, instrumentDocumentAndVariables, instrumentExecutionContext, instrumentExecutionInput, instrumentExecutionResult, instrumentSchemaMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface graphql.execution.instrumentation.Instrumentation
beginDeferredField
-
Constructor Details
-
CacheControlInstrumentation
public CacheControlInstrumentation() -
CacheControlInstrumentation
public CacheControlInstrumentation(int defaultMaxAge) -
CacheControlInstrumentation
public CacheControlInstrumentation(int defaultMaxAge, boolean allowZeroMaxAge)
-
-
Method Details
-
cacheControlHeaderFromGraphQLContext
@Nullable public static @Nullable String cacheControlHeaderFromGraphQLContext(graphql.GraphQLContext context) -
createState
public graphql.execution.instrumentation.InstrumentationState createState(graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters parameters) - Specified by:
createStatein interfacegraphql.execution.instrumentation.Instrumentation- Overrides:
createStatein classgraphql.execution.instrumentation.SimplePerformantInstrumentation
-
beginExecution
public graphql.execution.instrumentation.InstrumentationContext<graphql.ExecutionResult> beginExecution(graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters parameters, graphql.execution.instrumentation.InstrumentationState state) - Specified by:
beginExecutionin interfacegraphql.execution.instrumentation.Instrumentation- Overrides:
beginExecutionin classgraphql.execution.instrumentation.SimplePerformantInstrumentation
-
beginFieldExecution
@Nullable public @Nullable graphql.execution.instrumentation.InstrumentationContext<Object> beginFieldExecution(graphql.execution.instrumentation.parameters.InstrumentationFieldParameters parameters, graphql.execution.instrumentation.InstrumentationState state) - Specified by:
beginFieldExecutionin interfacegraphql.execution.instrumentation.Instrumentation- Overrides:
beginFieldExecutionin classgraphql.execution.instrumentation.SimplePerformantInstrumentation
-