Class GraphqlServiceContexts

java.lang.Object
com.linecorp.armeria.server.graphql.GraphqlServiceContexts

@UnstableApi public final class GraphqlServiceContexts extends Object
Retrieves the current ServiceRequestContext from a GraphQLContext or DataFetchingEnvironment.
  • Method Details

    • get

      public static ServiceRequestContext get(graphql.GraphQLContext graphQLContext)
      Retrieves the current ServiceRequestContext from the specified GraphQLContext. For example:
      
       new DataFetcher<>() {
           @Override
           public String get(DataFetchingEnvironment env) throws Exception {
               final GraphQLContext graphQLContext = env.getGraphQlContext();
               final ServiceRequestContext ctx = GraphqlServiceContexts.get(graphQLContext);
               // ...
           }
       };
       
      Throws:
      IllegalStateException - if the specified GraphQLContext doesn't contain a ServiceRequestContext.
    • get

      public static ServiceRequestContext get(graphql.schema.DataFetchingEnvironment environment)
      Retrieves the current ServiceRequestContext from the specified DataFetchingEnvironment. For example:
      
       new DataFetcher<>() {
           @Override
           public String get(DataFetchingEnvironment env) throws Exception {
               final ServiceRequestContext ctx = GraphqlServiceContexts.get(env);
               // ...
           }
       };
       
      Throws:
      IllegalStateException - if the specified DataFetchingEnvironment doesn't contain a ServiceRequestContext.