Search in sources :

Example 1 with QueryRunner

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());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) List(java.util.List) Elide(com.yahoo.elide.Elide) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) QueryRunner(com.yahoo.elide.graphql.QueryRunner) Callable(java.util.concurrent.Callable) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with QueryRunner

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;
}
Also used : User(com.yahoo.elide.core.security.User) ElideResponse(com.yahoo.elide.ElideResponse) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) UUID(java.util.UUID) QueryRunner(com.yahoo.elide.graphql.QueryRunner)

Aggregations

ElideResponse (com.yahoo.elide.ElideResponse)2 InvalidOperationException (com.yahoo.elide.core.exceptions.InvalidOperationException)2 User (com.yahoo.elide.core.security.User)2 QueryRunner (com.yahoo.elide.graphql.QueryRunner)2 Elide (com.yahoo.elide.Elide)1 AuthenticationUser (com.yahoo.elide.spring.security.AuthenticationUser)1 List (java.util.List)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1