use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testQueryWithNullVariableType.
@Test
public void testQueryWithNullVariableType() throws Exception {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcher fooDataFetcher = new GraphQLFooDataFetcher();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(fooDataFetcher).build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
String fooQuery = "{foo}";
// when
Object fooResult1 = controller.doGet(fooQuery, "{\"value\": \"Bar\"}");
Object fooResult2 = controller.doGet(fooQuery, null);
// then
Asserts.assertEquals(fooResult1.toString(), "{foo=Foo {value=Bar}}");
Asserts.assertEquals(fooResult2.toString(), "{foo=Foo null}");
}
use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser 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.GraphQLSchemaParser in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testFetcherNotFoundException.
@Test
public void testFetcherNotFoundException() {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
String heroQuery = "{hero}";
// when
Throwable e = Asserts.assertThrows(() -> controller.doGet(heroQuery, null));
// then
Asserts.assertEquals(HttpNotFoundException.class.toString(), e.getClass().toString());
}
use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser 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.GraphQLSchemaParser in project ezyhttp by youngmonkeys.
the class GraphQLSchemaParserTest method testZeroNameLength.
@Test
public void testZeroNameLength() {
// given
GraphQLSchemaParser parser = new GraphQLSchemaParser();
String query = "{q1 q2{{}}}";
// when
GraphQLSchema schema = parser.parseQuery(query);
// then
Asserts.assertEquals(schema.getQueryDefinitions().size(), 2);
Asserts.assertEquals(schema.getQueryDefinitions().get(0).getName(), "q1");
Asserts.assertEquals(schema.getQueryDefinitions().get(1).getName(), "q2");
Asserts.assertEquals(schema.getQueryDefinitions().get(1).getFields().get(0).getName(), null);
Asserts.assertEquals(schema.getQueryDefinitions().get(1).getFields().get(0).getFields().get(0).getName(), null);
}
Aggregations