com.networknt.graphql.router.handlers.GraphqlGetHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graphql-router Show documentation
Show all versions of graphql-router Show documentation
A route handler for GraphQL endpoint
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);
}
}