@Produces(value="application/json") public class GraphqlResourceBase extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static String |
APPLICATION_GRAPHQL |
protected AuthorizationService |
authorizationService |
protected GraphqlCache |
graphqlCache |
protected Persistence |
persistence |
| Constructor and Description |
|---|
GraphqlResourceBase() |
| Modifier and Type | Method and Description |
|---|---|
protected static void |
executeAsync(graphql.ExecutionInput input,
graphql.GraphQL graphql,
javax.ws.rs.container.AsyncResponse asyncResponse) |
protected void |
get(String query,
String operationName,
String variables,
graphql.GraphQL graphql,
javax.servlet.http.HttpServletRequest httpRequest,
javax.ws.rs.container.AsyncResponse asyncResponse)
Handles a GraphQL GET request.
|
protected boolean |
isAuthorized(javax.servlet.http.HttpServletRequest httpRequest,
String keyspaceName) |
protected void |
postGraphql(String query,
graphql.GraphQL graphql,
javax.servlet.http.HttpServletRequest httpRequest,
javax.ws.rs.container.AsyncResponse asyncResponse)
Handles a GraphQL POST request that uses the "application/graphql" content type.
|
protected void |
postJson(GraphqlJsonBody jsonBody,
String queryFromUrl,
graphql.GraphQL graphql,
javax.servlet.http.HttpServletRequest httpRequest,
javax.ws.rs.container.AsyncResponse asyncResponse)
Handles a GraphQL POST request that uses the
MediaType.APPLICATION_JSON content type. |
protected void |
postMultipartJson(GraphqlJsonBody jsonBody,
org.glassfish.jersey.media.multipart.FormDataMultiPart allParts,
graphql.GraphQL graphql,
javax.servlet.http.HttpServletRequest httpRequest,
javax.ws.rs.container.AsyncResponse asyncResponse)
Handles a GraphQL POST request that uses the
MediaType.MULTIPART_FORM_DATA content
type, allowing file arguments. |
protected static void |
replyWithGraphqlError(javax.ws.rs.core.Response.Status status,
graphql.GraphqlErrorException error,
javax.ws.rs.container.AsyncResponse asyncResponse) |
protected static void |
replyWithGraphqlError(javax.ws.rs.core.Response.Status status,
String message,
javax.ws.rs.container.AsyncResponse asyncResponse) |
protected static final String APPLICATION_GRAPHQL
@Inject protected AuthorizationService authorizationService
@Inject protected Persistence persistence
@Inject protected GraphqlCache graphqlCache
protected void get(String query, String operationName, String variables, graphql.GraphQL graphql, javax.servlet.http.HttpServletRequest httpRequest, javax.ws.rs.container.AsyncResponse asyncResponse)
The payload is provided via URL parameters.
protected void postJson(GraphqlJsonBody jsonBody, String queryFromUrl, graphql.GraphQL graphql, javax.servlet.http.HttpServletRequest httpRequest, javax.ws.rs.container.AsyncResponse asyncResponse)
MediaType.APPLICATION_JSON content type.
Such a request normally comprises a JSON-encoded body, but the spec also allows the query to be passed as a URL parameter.
protected void postMultipartJson(GraphqlJsonBody jsonBody, org.glassfish.jersey.media.multipart.FormDataMultiPart allParts, graphql.GraphQL graphql, javax.servlet.http.HttpServletRequest httpRequest, javax.ws.rs.container.AsyncResponse asyncResponse)
MediaType.MULTIPART_FORM_DATA content
type, allowing file arguments.
It follows the GraphQL multipart request specification.
Example cURL call:
curl http://host:port/path/to/graphql \
-F operations='{ "query": "query ($file: Upload!) { someQuery(file: $file) }", "variables": { "file": null } };type=application/json'
-F map='{ "filePart": ["variables.file"] }'
-FfilePart=@/path/to/file.txt
The first part MUST declare a JSON content type ("type=application/json" in the example above).
This method assumes that its argument come from properly annotated arguments in a Jersey resource; see the existing callers for an example.
jsonBody - the JSON payload containing the GraphQL "operations object" to execute (eg
{query=..., variables=...}). It's parsed from the operations
part in the request.allParts - the whole multipart request, consisting of: the operations part
(ignored since we've already parsed it above), a map part containing a map
that specifies which GraphQL variable each file corresponds to, and an arbitrary number of
file parts named after the keys of the files map.graphql - the GraphQL schema to use for execution.protected void postGraphql(String query, graphql.GraphQL graphql, javax.servlet.http.HttpServletRequest httpRequest, javax.ws.rs.container.AsyncResponse asyncResponse)
The request body is the GraphQL query directly.
protected static void executeAsync(graphql.ExecutionInput input,
graphql.GraphQL graphql,
@Suspended
javax.ws.rs.container.AsyncResponse asyncResponse)
protected boolean isAuthorized(javax.servlet.http.HttpServletRequest httpRequest,
String keyspaceName)
protected static void replyWithGraphqlError(javax.ws.rs.core.Response.Status status,
String message,
@Suspended
javax.ws.rs.container.AsyncResponse asyncResponse)
protected static void replyWithGraphqlError(javax.ws.rs.core.Response.Status status,
graphql.GraphqlErrorException error,
@Suspended
javax.ws.rs.container.AsyncResponse asyncResponse)
Copyright © 2022. All rights reserved.