use of com.yahoo.elide.graphql.QueryRunner in project elide by yahoo.
the class GraphqlController method post.
/**
* Single entry point for GraphQL requests.
*
* @param requestHeaders request headers
* @param graphQLDocument post data as json document
* @param principal The user principal
* @return response
*/
@PostMapping(value = { "/**", "" }, consumes = JSON_CONTENT_TYPE, produces = JSON_CONTENT_TYPE)
public Callable<ResponseEntity<String>> post(@RequestHeader HttpHeaders requestHeaders, @RequestBody String graphQLDocument, Authentication principal) {
final User user = new AuthenticationUser(principal);
final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
final QueryRunner runner = runners.getRunner(apiVersion);
final String baseUrl = getBaseUrlEndpoint();
return new Callable<ResponseEntity<String>>() {
@Override
public ResponseEntity<String> call() throws Exception {
ElideResponse response;
if (runner == null) {
response = buildErrorResponse(mapper, new InvalidOperationException("Invalid API Version"), false);
} else {
Elide elide = runner.getElide();
response = runner.run(baseUrl, graphQLDocument, user, UUID.randomUUID(), requestHeadersCleaned);
}
return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
}
};
}
use of com.yahoo.elide.graphql.QueryRunner in project elide by yahoo.
the class GraphQLAsyncQueryOperation method execute.
@Override
public ElideResponse execute(AsyncAPI queryObj, RequestScope scope) throws URISyntaxException {
User user = scope.getUser();
String apiVersion = scope.getApiVersion();
QueryRunner runner = getService().getRunners().get(apiVersion);
if (runner == null) {
throw new InvalidOperationException("Invalid API Version");
}
UUID requestUUID = UUID.fromString(queryObj.getRequestId());
// TODO - we need to add the baseUrlEndpoint to the queryObject.
ElideResponse response = runner.run("", queryObj.getQuery(), user, requestUUID, scope.getRequestHeaders());
log.debug("GRAPHQL_V1_0 getResponseCode: {}, GRAPHQL_V1_0 getBody: {}", response.getResponseCode(), response.getBody());
return response;
}
Aggregations