Search in sources :

Example 6 with GraphQLController

use of com.tvd12.ezyhttp.server.graphql.controller.GraphQLController in project ezyhttp by youngmonkeys.

the class GraphQLConfiguration method config.

@SuppressWarnings("rawtypes")
@Override
public void config() {
    GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
    GraphQLDataFetcherManager.Builder dataFetcherManagerBuilder = GraphQLDataFetcherManager.builder();
    List singletons = singletonFactory.getSingletons();
    for (Object singleton : singletons) {
        dataFetcherManagerBuilder.addDataFetcher(singleton);
    }
    GraphQLDataFetcherManager dataFetcherManager = dataFetcherManagerBuilder.build();
    GraphQLController controller = GraphQLController.builder().objectMapper(objectMapper).dataFetcherManager(dataFetcherManager).schemaParser(schemaParser).build();
    singletonFactory.addSingleton(controller);
}
Also used : GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) List(java.util.List)

Example 7 with GraphQLController

use of com.tvd12.ezyhttp.server.graphql.controller.GraphQLController in project ezyhttp by youngmonkeys.

the class GraphQLControllerTest method test.

@Test
public void test() throws Exception {
    // given
    GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
    GraphQLDataFetcher meDataFetcher = new GraphQLMeDataFetcher();
    GraphQLDataFetcher heroDataFetcher = new GraphQLHeroDataFetcher();
    GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(meDataFetcher).addDataFetcher(heroDataFetcher).build();
    ObjectMapper objectMapper = new ObjectMapper();
    GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
    GraphQLRequest meRequest = new GraphQLRequest();
    meRequest.setQuery("query{    me   {     name bank{id} friends{name} address}}");
    String heroQuery = "{hero}";
    // when
    Object meResult = controller.doPost(meRequest);
    Object heroResult = controller.doGet(heroQuery, null);
    // then
    Asserts.assertEquals(meResult.toString(), "{me={bank={id=1}, name=Dzung, friends=[{name=Foo}, {name=Bar}]}}");
    Asserts.assertEquals(heroResult.toString(), "{hero=Hero 007}");
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLRequest(com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest) GraphQLDataFetcher(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher) GraphQLDataFetcherManager(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager) GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)6 Test (org.testng.annotations.Test)6 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)5 GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)5 GraphQLRequest (com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest)3 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)1 EzySingletonFactory (com.tvd12.ezyfox.bean.EzySingletonFactory)1 HttpNotFoundException (com.tvd12.ezyhttp.core.exception.HttpNotFoundException)1 GraphQLConfiguration (com.tvd12.ezyhttp.server.graphql.GraphQLConfiguration)1 GraphQLInvalidSchemeException (com.tvd12.ezyhttp.server.graphql.exception.GraphQLInvalidSchemeException)1 Field (java.lang.reflect.Field)1 List (java.util.List)1 Map (java.util.Map)1