use of com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testQueryWithVariables.
@Test
public void testQueryWithVariables() throws Exception {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcher welcomeDataFetcher = new GraphQLWelcomeDataFetcher();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(welcomeDataFetcher).build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
String welcomeQuery = "{welcome}";
String variables = "{\"name\": \"Foo\"}";
GraphQLRequest welcomeRequest = new GraphQLRequest();
welcomeRequest.setQuery(welcomeQuery);
welcomeRequest.setVariables(variables);
// when
Object welcomeResult1 = controller.doGet(welcomeQuery, variables);
Object welcomeResult2 = controller.doPost(welcomeRequest);
// then
Asserts.assertEquals(welcomeResult1.toString(), "{welcome=Welcome Foo}");
Asserts.assertEquals(welcomeResult2.toString(), "{welcome=Welcome Foo}");
}
use of com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testInvalidScheme.
@Test
public void testInvalidScheme() {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcher meDataFetcher = new GraphQLYouDataFetcher();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(meDataFetcher).build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
GraphQLRequest youRequest = new GraphQLRequest();
youRequest.setQuery("query{you{friends{name}}}}");
// when
Throwable e = Asserts.assertThrows(() -> controller.doPost(youRequest));
// then
Asserts.assertEquals(GraphQLInvalidSchemeException.class.toString(), e.getClass().toString());
}
use of com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest 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