package io.leangen.spqr.samples.demo.controller;

import graphql.ExecutionInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import io.leangen.graphql.GraphQLSchemaGenerator;
import io.leangen.graphql.metadata.strategy.query.AnnotatedResolverBuilder;
import io.leangen.graphql.metadata.strategy.query.PublicResolverBuilder;
import io.leangen.graphql.metadata.strategy.value.jackson.JacksonValueMapperFactory;
import io.leangen.spqr.samples.demo.query.annotated.PersonQuery;
import io.leangen.spqr.samples.demo.query.annotated.SocialNetworkQuery;
import io.leangen.spqr.samples.demo.query.annotated.VendorQuery;
import io.leangen.spqr.samples.demo.query.unannotated.DomainQuery;
import io.leangen.spqr.samples.demo.query.unannotated.ProductQuery;

import javax.servlet.http.HttpServletRequest;

@RestController
public class GraphQLSampleController {
    private static final Logger LOGGER = LoggerFactory.getLogger(GraphQLSampleController.class);

    private final GraphQL graphQL;

    @Autowired
    public GraphQLSampleController(PersonQuery personQuery,
                                   SocialNetworkQuery socialNetworkQuery,
                                   DomainQuery domainQuery,
                                   ProductQuery productQuery,
                                   VendorQuery vendorQuery) {

        //Schema generated from query classes
        GraphQLSchema schema = new GraphQLSchemaGenerator()
                .withResolverBuilders(
                        //Resolve by annotations
                        new AnnotatedResolverBuilder(),
                        //Resolve public methods inside root package
                        new PublicResolverBuilder("io.leangen.spqr.samples.demo"))
                .withOperationsFromSingleton(personQuery)
                .withOperationsFromSingleton(socialNetworkQuery)
                .withOperationsFromSingleton(vendorQuery)
                .withOperationsFromSingleton(domainQuery)
                .withOperationsFromSingleton(productQuery)
                .withValueMapperFactory(new JacksonValueMapperFactory())
                .generate();
        graphQL = GraphQL.newGraphQL(schema).build();

        LOGGER.info("Generated GraphQL schema using SPQR");
    }

    @PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Map<String, Object> indexFromAnnotated(@RequestBody Map<String, String> request, HttpServletRequest raw) {
        ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput()
                .query(request.get("query"))
                .operationName(request.get("operationName"))
                .context(raw)
                .build());
        return executionResult.toSpecification();
    }
}
@@ -78,439 +78,8 @@
 ut;%0A
-import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.http.MediaType;%0Aimport org.springframework.web.bind.annotation.PostMapping;%0Aimport org.springframework.web.bind.annotation.RequestBody;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0Aimport org.springframework.web.bind.annotation.RestController;%0A%0Aimport java.util.Map;%0A%0A
 impo
@@ -239,49 +239,41 @@
 gen.
-graphql.metadata.strategy
+spqr.samples.demo
 .query.
-A
+a
 nnotated
 Reso
@@ -268,31 +268,28 @@
 nnotated
-ResolverBuild
+.PersonQu
 er
+y
 ;%0Aimport
@@ -304,61 +304,60 @@
 gen.
-graphql.metadata.strategy.query.PublicResolverBuild
+spqr.samples.demo.query.annotated.SocialNetworkQu
 er
+y
 ;%0Aim
@@ -376,71 +376,51 @@
 gen.
-graphql.metadata.strategy.value.jackson.JacksonValueMapperFacto
+spqr.samples.demo.query.annotated.VendorQue
 ry;%0A
@@ -453,32 +453,34 @@
 ples.demo.query.
+un
 annotated.Person
@@ -465,37 +465,37 @@
 ery.unannotated.
-Perso
+Domai
 nQuery;%0Aimport i
@@ -520,32 +520,34 @@
 ples.demo.query.
+un
 annotated.Social
@@ -536,37 +536,31 @@
 unannotated.
-SocialNetwork
+Product
 Query;%0Aimpor
@@ -565,199 +565,406 @@
 ort 
-io.leangen.spqr.samples.demo.query.annotated.VendorQuery;%0Aimport io.leangen.spqr.samples.demo.query.unannotated.DomainQuery;%0Aimport io.leangen.spqr.samples.demo.query.unannotated.ProductQu
+org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.http.MediaType;%0Aimport org.springframework.web.bind.annotation.PostMapping;%0Aimport org.springframework.web.bind.annotation.RequestBody;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0Aimport org.springframework.web.bind.annotation.RestControll
 er
-y
 ;%0A%0Ai
@@ -1007,16 +1007,38 @@
 Request;
+%0Aimport java.util.Map;
 %0A%0A@RestC
@@ -1664,304 +1664,8 @@
 r()%0A
-                .withResolverBuilders(%0A                        //Resolve by annotations%0A                        new AnnotatedResolverBuilder(),%0A                        //Resolve public methods inside root package%0A                        new PublicResolverBuilder(%22io.leangen.spqr.samples.demo%22))%0A
     
@@ -1704,16 +1704,17 @@
 ingleton
+s
 (personQ
@@ -1721,321 +1721,68 @@
 uery
-)%0A                .withOperationsFromSingleton(socialNetworkQuery)%0A                .withOperationsFromSingleton(vendorQuery)%0A                .withOperationsFromSingleton(domainQuery)%0A                .withOperationsFromSingleton(productQuery)%0A                .withValueMapperFactory(new JacksonValueMapperFactory()
+, socialNetworkQuery, vendorQuery, domainQuery, productQuery
 )%0A  
@@ -2516,8 +2516,9 @@
 %0A    %7D%0A%7D
+%0A

Removed the redundant lines