io.micronaut.http.annotation.QueryValue Java Examples

The following examples show how to use io.micronaut.http.annotation.QueryValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphQLController.java    From micronaut-graphql with Apache License 2.0 5 votes vote down vote up
/**
 * Handles GraphQL {@code GET} requests.
 *
 * @param query         the GraphQL query
 * @param operationName the GraphQL operation name
 * @param variables     the GraphQL variables
 * @param httpRequest   the HTTP request
 * @return the GraphQL response
 */
@Get(produces = APPLICATION_JSON, single = true)
public Publisher<String> get(
        @QueryValue("query") String query,
        @Nullable @QueryValue("operationName") String operationName,
        @Nullable @QueryValue("variables") String variables,
        HttpRequest httpRequest) {

    // https://graphql.org/learn/serving-over-http/#get-request
    //
    // When receiving an HTTP GET request, the GraphQL query should be specified in the "query" query string.
    // For example, if we wanted to execute the following GraphQL query:
    //
    // {
    //   me {
    //     name
    //   }
    // }
    //
    // This request could be sent via an HTTP GET like so:
    //
    // http://myapi/graphql?query={me{name}}
    //
    // Query variables can be sent as a JSON-encoded string in an additional query parameter called "variables".
    // If the query contains several named operations,
    // an "operationName" query parameter can be used to control which one should be executed.

    return executeRequest(query, operationName, convertVariablesJson(variables), httpRequest);
}
 
Example #2
Source File: Database.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Get("/updates")
public Single<List<World>> updates(@QueryValue String queries) {
    Flowable<World>[] worlds = new Flowable[parseQueryCount(queries)];

    Arrays.setAll(worlds, i ->
            dbRepository.findAndUpdateWorld(randomWorldNumber(), randomWorldNumber()).toFlowable()
    );

    return Flowable.merge(Arrays.asList(worlds)).toList();
}
 
Example #3
Source File: BookClient.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Get("/{title}")
Page<Book> findByTitleLike(
        String title,
        @QueryValue int page,
        @QueryValue int size,
        @QueryValue(defaultValue = "title, desc") String sort);
 
Example #4
Source File: PolicySearchOperations.java    From micronaut-microservices-poc with Apache License 2.0 4 votes vote down vote up
@Get
Maybe<FindPolicyQueryResult> policies(@QueryValue("q") String queryText);
 
Example #5
Source File: PolicySearchTestClient.java    From micronaut-microservices-poc with Apache License 2.0 4 votes vote down vote up
@Get
Maybe<FindPolicyQueryResult> policies(@QueryValue("q") String queryText);
 
Example #6
Source File: PolicyGatewayController.java    From micronaut-microservices-poc with Apache License 2.0 4 votes vote down vote up
@Get
Maybe<FindPolicyQueryResult> policies(@QueryValue(value = "q", defaultValue = "*") String q) {
    return policySearchClient.policies(q);
}
 
Example #7
Source File: GraphQLController.java    From micronaut-graphql with Apache License 2.0 4 votes vote down vote up
/**
 * Handles GraphQL {@code POST} requests.
 *
 * @param query         the GraphQL query
 * @param operationName the GraphQL operation name
 * @param variables     the GraphQL variables
 * @param body          the GraphQL request body
 * @param httpRequest   the HTTP request
 * @return the GraphQL response
 */
@Post(consumes = ALL, produces = APPLICATION_JSON, single = true)
public Publisher<String> post(
        @Nullable @QueryValue("query") String query,
        @Nullable @QueryValue("operationName") String operationName,
        @Nullable @QueryValue("variables") String variables,
        @Nullable @Body String body,
        HttpRequest httpRequest) {

    Optional<MediaType> opt = httpRequest.getContentType();
    MediaType contentType = opt.orElse(null);

    if (body == null) {
        body = "";
    }

    // https://graphql.org/learn/serving-over-http/#post-request
    //
    // A standard GraphQL POST request should use the application/json content type,
    // and include a JSON-encoded body of the following form:
    //
    // {
    //   "query": "...",
    //   "operationName": "...",
    //   "variables": { "myVariable": "someValue", ... }
    // }

    if (APPLICATION_JSON_TYPE.equals(contentType)) {
        GraphQLRequestBody request = graphQLJsonSerializer.deserialize(body, GraphQLRequestBody.class);
        if (request.getQuery() == null) {
            request.setQuery("");
        }
        return executeRequest(request.getQuery(), request.getOperationName(), request.getVariables(), httpRequest);
    }

    // In addition to the above, we recommend supporting two additional cases:
    //
    // * If the "query" query string parameter is present (as in the GET example above),
    //   it should be parsed and handled in the same way as the HTTP GET case.

    if (query != null) {
        return executeRequest(query, operationName, convertVariablesJson(variables), httpRequest);
    }

    // * If the "application/graphql" Content-Type header is present,
    //   treat the HTTP POST body contents as the GraphQL query string.

    if (APPLICATION_GRAPHQL_TYPE.equals(contentType)) {
        return executeRequest(body, null, null, httpRequest);
    }

    throw new HttpStatusException(UNPROCESSABLE_ENTITY, "Could not process GraphQL request");
}
 
Example #8
Source File: RequestParamAnnotationMapper.java    From micronaut-spring with Apache License 2.0 4 votes vote down vote up
@Override
Class<QueryValue> annotationType() {
    return QueryValue.class;
}