net.morimekta.providence.graphql.GQLSchemaServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of providence-graphql Show documentation
Show all versions of providence-graphql Show documentation
Providence Core extension for GraphQL.
package net.morimekta.providence.graphql;
import javax.annotation.Nonnull;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* A servlet for serving graphql given a GQL service and associated providers.
*
* Spec for serving GraphQL over HTTP can be found here.
*/
public class GQLSchemaServlet extends HttpServlet {
private static final String MEDIA_TYPE = "text/plain";
private final GQLDefinition definition;
public GQLSchemaServlet(@Nonnull GQLDefinition definition) {
this.definition = definition;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setStatus(HttpServletResponse.SC_OK);
resp.setHeader("Content-Type", MEDIA_TYPE);
resp.getWriter().write(definition.getSchema());
}
}