Class GraphQlRSocketHandler

java.lang.Object
org.springframework.graphql.server.GraphQlRSocketHandler

public class GraphQlRSocketHandler extends Object
Handler for GraphQL over RSocket requests.

This class can be extended or wrapped from an @Controller in order to re-declare handle(Map) and handleSubscription(Map) with @MessageMapping annotations including the GraphQL endpoint route.

 @Controller
 private static class GraphQlRSocketController {

    private final GraphQlRSocketHandler handler;

    GraphQlRSocketController(GraphQlRSocketHandler handler) {
        this.handler = handler;
    }

    @MessageMapping("graphql")
    public Mono<Map<String, Object>> handle(Map<String, Object> payload) {
        return this.handler.handle(payload);
    }

    @MessageMapping("graphql")
    public Flux<Map<String, Object>> handleSubscription(Map<String, Object> payload) {
        return this.handler.handleSubscription(payload);
    }
 }
 
Since:
1.0.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • GraphQlRSocketHandler

      public GraphQlRSocketHandler(ExecutionGraphQlService graphQlService, List<RSocketGraphQlInterceptor> interceptors, Encoder<?> jsonEncoder)
      Create a new instance that handles requests through a chain of interceptors followed by the given ExecutionGraphQlService.
      Parameters:
      graphQlService - the service that will execute the request
      interceptors - interceptors to form the processing chain
      jsonEncoder - a JSON encoder for serializing a GraphQLError list for a failed subscription
  • Method Details

    • handle

      public reactor.core.publisher.Mono<Map<String,Object>> handle(Map<String,Object> payload)
      Handle a Request-Response interaction. For queries and mutations.
    • handleSubscription

      public reactor.core.publisher.Flux<Map<String,Object>> handleSubscription(Map<String,Object> payload)
      Handle a Request-Stream interaction. For subscriptions.