Search in sources :

Example 1 with GraphQLRequest

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

Example 2 with GraphQLRequest

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());
}
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) GraphQLInvalidSchemeException(com.tvd12.ezyhttp.server.graphql.exception.GraphQLInvalidSchemeException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 3 with GraphQLRequest

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

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)3 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)3 GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)3 GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)3 GraphQLRequest (com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest)3 Test (org.testng.annotations.Test)3 GraphQLInvalidSchemeException (com.tvd12.ezyhttp.server.graphql.exception.GraphQLInvalidSchemeException)1