public final class GraphQL
- Object
- 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
Inherited methods
Field details
CONTENT_TYPE
public static final String CONTENT_TYPE = "application/json"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)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)encodeVariables
public static String encodeVariables(Map<String, Object> variables)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)GraphQLResponse. Public and side-effect free so unit tests can
replay canned bodies without a network round-trip.