package de.verteiltearchitekturen.graphql;

import javax.servlet.annotation.WebServlet;
import graphql.kickstart.servlet.GraphQLConfiguration;
import graphql.kickstart.servlet.GraphQLHttpServlet;
import graphql.kickstart.tools.SchemaParser;
import graphql.schema.GraphQLSchema;

@SuppressWarnings("serial")
@WebServlet(urlPatterns = "/graphql")
public class GraphQLEndpoint extends GraphQLHttpServlet {

    @Override
    protected GraphQLConfiguration getConfiguration() {
        return GraphQLConfiguration.with(createSchema()).build();
    }

    static GraphQLSchema createSchema() {
        return SchemaParser //
                .newParser() //
                .file("schema.graphqls")//
                .resolvers(new Query(), new Mutation()) //
                .build()//
                .makeExecutableSchema();
    }

}