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);
}
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}");
}
Aggregations