All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.graphql.router.handlers.GraphqlGetHandler Maven / Gradle / Ivy

The newest version!
package com.networknt.graphql.router.handlers;

import com.networknt.graphql.common.GraphqlUtil;
import com.networknt.graphql.router.RenderGraphiQL;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import io.undertow.util.StatusCodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * This is the handler to handle graphql get request.
 *
 * @author Steve Hu
 */
public class GraphqlGetHandler implements HttpHandler {

    private static final Logger logger = LoggerFactory.getLogger(GraphqlGetHandler.class);

    @Override
    public void handleRequest(HttpServerExchange exchange) {
        @SuppressWarnings("unchecked")
        Map requestParameters = (Map)exchange.getAttachment(GraphqlUtil.GRAPHQL_PARAMS);
        if(logger.isDebugEnabled()) logger.debug("requestParameters: " + requestParameters);
        String graphiql = RenderGraphiQL.render(requestParameters, null);
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8");
        exchange.setStatusCode(StatusCodes.OK);
        exchange.getResponseSender().send(graphiql);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy