public final class GraphQL

  1. Object
  2. GraphQL

High-level GraphQL-over-HTTP invoker used by generated @GraphQLClient implementations. Queries and mutations are sent as an HTTP POST with a JSON body {"query":...,"operationName":...,"variables":{...}} and a Content-Type: application/json header; the JSON response envelope ({"data":...,"errors":[...]}) is parsed into a typed GraphQLResponse. Subscriptions are delegated to GraphQLSubscription over a WebSocket.

Mirrors GrpcWeb. All methods are static; generated impls call execute / subscribe and never touch ConnectionRequest directly.

Fields

public static final String CONTENT_TYPE = "application/json"Content type for GraphQL-over-HTTP requests.

Methods

public static <T> void execute(String endpoint, String bearerToken, String operationName, String document, Map<String, Object> variables, Class<T> dataType, OnComplete<GraphQLResponse<T>> callback)Sends a unary query or mutation and invokes callback with the decoded GraphQLResponse.
public static <T> GraphQLSubscription subscribe(String endpoint, String bearerToken, String operationName, String document, Map<String, Object> variables, Class<T> dataType, GraphQLSubscription.Handler<T> handler)Opens a GraphQL subscription over a WebSocket and streams mapped data payloads to handler.
public static String buildRequestBody(String operationName, String document, Map<String, Object> variables)Builds the JSON request body.
public static String encodeVariables(Map<String, Object> variables)Serialises a variable-name -> value map to a JSON object string.
public static <T> GraphQLResponse<T> decodeJson(byte[] body, int httpCode, Class<T> dataType)Decodes a GraphQL JSON response envelope into a typed GraphQLResponse.

Inherited methods

Field details

CONTENT_TYPE

public static final String CONTENT_TYPE = "application/json"
Content type for GraphQL-over-HTTP requests.

Method details

execute

public static <T> void execute(String endpoint, String bearerToken, String operationName, String document, Map<String, Object> variables, Class<T> dataType, OnComplete<GraphQLResponse<T>> callback)
Sends a unary query or mutation and invokes callback with the decoded GraphQLResponse. variables may be null or empty. The operationName may be null when the document declares a single operation.

subscribe

public static <T> GraphQLSubscription subscribe(String endpoint, String bearerToken, String operationName, String document, Map<String, Object> variables, Class<T> dataType, GraphQLSubscription.Handler<T> handler)

Opens a GraphQL subscription over a WebSocket and streams mapped data payloads to handler. Returns a handle whose GraphQLSubscription.cancel() tears the subscription down.

The endpoint is the GraphQL HTTP endpoint; its scheme is rewritten to ws/wss for the WebSocket connection. Pass a ws:///wss:// URL directly to override that heuristic.

buildRequestBody

public static String buildRequestBody(String operationName, String document, Map<String, Object> variables)
Builds the JSON request body. Public so tests can verify it without the network path.

encodeVariables

public static String encodeVariables(Map<String, Object> variables)
Serialises a variable-name -> value map to a JSON object string. Strings, numbers, booleans, Lists, Maps and null pass through the framework JSON writer; enums serialise as their name(); any other object is assumed to be @Mapped and is converted via Mappers.toJson(Object) and spliced in verbatim. Public so generated impls and tests can reuse it.

decodeJson

public static <T> GraphQLResponse<T> decodeJson(byte[] body, int httpCode, Class<T> dataType)
Decodes a GraphQL JSON response envelope into a typed GraphQLResponse. Public and side-effect free so unit tests can replay canned bodies without a network round-trip.