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

    Constructors
    Constructor
    Description
     
    CacheControlInstrumentation(int defaultMaxAge)
     
    CacheControlInstrumentation(int defaultMaxAge, boolean allowZeroMaxAge)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    graphql.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 String
    cacheControlHeaderFromGraphQLContext(graphql.GraphQLContext context)
     
    graphql.execution.instrumentation.InstrumentationState
    createState(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, instrumentSchema

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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:
      createState in interface graphql.execution.instrumentation.Instrumentation
      Overrides:
      createState in class graphql.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:
      beginExecution in interface graphql.execution.instrumentation.Instrumentation
      Overrides:
      beginExecution in class graphql.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:
      beginFieldExecution in interface graphql.execution.instrumentation.Instrumentation
      Overrides:
      beginFieldExecution in class graphql.execution.instrumentation.SimplePerformantInstrumentation