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

net.morimekta.providence.graphql.GQLSchemaServlet Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy