Package manifold.graphql.rt.api.request
Class Executor<T>
- java.lang.Object
-
- manifold.graphql.rt.api.request.Executor<T>
-
- Type Parameters:
T-
public class Executor<T> extends Object
Based on: "How to make GraphQL HTTP request using cUrl" Based on the GET/POST and the Content-Type header, it expects the input params differently. This behaviour was ported from express-graphql. So given the following operation:mutation M { newTodo: createTodo(text: "This is a mutation example") { text done } }using GET $ curl -g -GET 'http://localhost:8080/graphql?query=mutation+M{newTodo:createTodo(text:"This+is+a+mutation+example"){text+done}}' using POST + Content-Type: application/graphql $ curl -XPOST http://localhost:8080/graphql -H 'Content-Type: application/graphql' -d 'mutation M { newTodo: createTodo(text: "This is a mutation example") { text done } }' using POST + Content-Type: application/json $ curl -XPOST http://localhost:8080/graphql -H 'Content-Type: application/json' -d '{"query": "mutation M { newTodo: createTodo(text: \"This is a mutation example\") { text done } }"}'
-
-
Constructor Summary
Constructors Constructor Description Executor(String url, String operation, String query, manifold.rt.api.Bindings variables, Class<T> resultType)Executor(Supplier<manifold.json.rt.api.Requester<manifold.rt.api.Bindings>> requester, String operation, String query, manifold.rt.api.Bindings variables, Class<T> resultType)Executor(manifold.json.rt.api.Endpoint endpoint, String operation, String query, manifold.rt.api.Bindings variables, Class<T> resultType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()Make an HTTP GET request tourl.Tget(manifold.json.rt.api.Requester.Format format)Make an HTTP GET request tourl.manifold.json.rt.api.EndpointgetEndpoint()Access the GraphQL request endpoint.manifold.json.rt.api.Requester.FormatgetFormat()Access the GraphQL request format.Map<String,String>getHeaders()Access an unmodifiable view of the GraphQL request headers.Function<manifold.rt.api.Bindings,Object>getRawResponseHandler()GqlRequestBodygetRequestBody()Access the full GraphQL request body, which includesqueryandvariablesbindings.intgetTimeout()Access the GraphqL request timeout.Tpost()Make an HTTP POST request tourl.Tpost(manifold.json.rt.api.Requester.Format format)Make an HTTP POST request tourl.Executor<T>withAuthorization(String tokenType, String accessToken)Executor<T>withBasicAuthorization(String username, String password)Set the Basic Authorization header using the providedusernameandpasswordExecutor<T>withBearerAuthorization(String accessToken)Set the Bearer Authorization header using the providedaccessToken.Executor<T>withHeader(String name, String value)Set an HTTP request headername : valuepair See HTTP header fieldsExecutor<T>withParam(String name, String value)Add aname=valueparameter to the request URL.Executor<T>withRawResponseHandler(Function<manifold.rt.api.Bindings,Object> handler)Executor<T>withTimeout(int timeout)The connection timeout setting in milliseconds.
-
-
-
Constructor Detail
-
Executor
public Executor(String url, String operation, String query, manifold.rt.api.Bindings variables, Class<T> resultType)
-
Executor
public Executor(manifold.json.rt.api.Endpoint endpoint, String operation, String query, manifold.rt.api.Bindings variables, Class<T> resultType)
-
-
Method Detail
-
getRequestBody
public GqlRequestBody getRequestBody()
Access the full GraphQL request body, which includesqueryandvariablesbindings.- Returns:
- the GraphQL request body consisting of bindings for both the query and variables.
-
getHeaders
public Map<String,String> getHeaders()
Access an unmodifiable view of the GraphQL request headers.
-
getEndpoint
public manifold.json.rt.api.Endpoint getEndpoint()
Access the GraphQL request endpoint.
-
getFormat
public manifold.json.rt.api.Requester.Format getFormat()
Access the GraphQL request format.
-
getTimeout
public int getTimeout()
Access the GraphqL request timeout.
-
withHeader
public Executor<T> withHeader(String name, String value)
Set an HTTP request headername : valuepair See HTTP header fields
-
withParam
public Executor<T> withParam(String name, String value)
Add aname=valueparameter to the request URL.
-
withBasicAuthorization
public Executor<T> withBasicAuthorization(String username, String password)
Set the Basic Authorization header using the providedusernameandpassword
-
withBearerAuthorization
public Executor<T> withBearerAuthorization(String accessToken)
Set the Bearer Authorization header using the providedaccessToken. For instance, if using OAuth,accessTokenis the token response from:curl -d "grant_type=password&client_id=[...]&client_secret=[...]&username=[...]&password=[...]" https://[domain]/[oauth-service]
-
withTimeout
public Executor<T> withTimeout(int timeout)
The connection timeout setting in milliseconds. If the timeout expires before the connection can be established, a {@link java.net.SocketTimeoutException) is thrown. A value of zero is interpreted as an infinite timeout, this is the default setting.
-
withRawResponseHandler
public Executor<T> withRawResponseHandler(Function<manifold.rt.api.Bindings,Object> handler)
- Parameters:
handler- An optional handler for processing the raw response as an arbitrary Bindings instance. The handler may return a custom bindings object which overrides the default, type-safe result instance. In any case, the handler can process the response in any way. Note, modifications made to the response persist and, therefore, affect default internal data and error processing.- Returns:
- this
Executorinstance.
-
post
public T post() throws GqlRequestException
Make an HTTP POST request tourl. Thepayload, if non-null, is sent as JSON encoded text in the request's message body.- Returns:
- A JSON value parsed from the
formatspecified encoded response (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value) - Throws:
GqlRequestException- If the response contains errors, wraps them in a list ofGqlErrorand throws
-
post
public T post(manifold.json.rt.api.Requester.Format format) throws GqlRequestException
Make an HTTP POST request tourl. Thepayload, if non-null, is sent as JSON encoded text in the request's message body.- Parameters:
format- The expected format of the response. One of:Json,Yaml, orPlain- Returns:
- A JSON value parsed from the
formatspecified encoded response (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value) - Throws:
GqlRequestException- If the response contains errors, wraps them in a list ofGqlErrorand throws
-
get
public T get() throws GqlRequestException
Make an HTTP GET request tourl. Thepayload, if non-null, is sent as JSON encoded text in the request's message body.- Returns:
- A JSON value parsed from the
formatspecified encoded response (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value) - Throws:
GqlRequestException- If the response contains errors, wraps them in a list ofGqlErrorand throws
-
get
public T get(manifold.json.rt.api.Requester.Format format) throws GqlRequestException
Make an HTTP GET request tourl. Thepayload, if non-null, is sent as JSON encoded text in the request's message body.- Parameters:
format- The expected format of the response. One of:Json,Yaml, orPlain- Returns:
- A JSON value parsed from the
formatspecified encoded response (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value) - Throws:
GqlRequestException- If the response contains errors, wraps them in a list ofGqlErrorand throws
-
-