Class 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(String, String, String, String, Map, Class, OnComplete) / subscribe(String, String, String, String, Map, Class, GraphQLSubscription.Handler) and never touch
ConnectionRequest directly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringContent type for GraphQL-over-HTTP requests. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilds the JSON request body.static <T> GraphQLResponse<T> decodeJson(byte[] body, int httpCode, Class<T> dataType) Decodes a GraphQL JSON response envelope into a typedGraphQLResponse.static StringencodeVariables(Map<String, Object> variables) Serialises a variable-name -> value map to a JSON object string.static <T> voidexecute(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 invokescallbackwith the decodedGraphQLResponse.static <T> GraphQLSubscriptionsubscribe(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 mappeddatapayloads tohandler.
-
Field Details
-
CONTENT_TYPE
-
-
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 invokescallbackwith the decodedGraphQLResponse.variablesmay be null or empty. TheoperationNamemay 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
datapayloads tohandler. Returns a handle whoseGraphQLSubscription.cancel()tears the subscription down.The
endpointis the GraphQL HTTP endpoint; its scheme is rewritten tows/wssfor the WebSocket connection. Pass aws:///wss://URL directly to override that heuristic. -
buildRequestBody
-
encodeVariables
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 theirname(); any other object is assumed to be@Mappedand is converted viaMappers.toJson(Object)and spliced in verbatim. Public so generated impls and tests can reuse it. -
decodeJson
Decodes a GraphQL JSON response envelope into a typedGraphQLResponse. Public and side-effect free so unit tests can replay canned bodies without a network round-trip.
-