use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser 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.GraphQLSchemaParser in project ezyhttp by youngmonkeys.
the class GraphQLSchemaParserTest method testParseSchema2.
@Test
public void testParseSchema2() {
// 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");
}
use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.
the class GraphQLSchemaParserTest method testStandardize5.
@Test
public void testStandardize5() {
// given
GraphQLSchemaParser parser = new GraphQLSchemaParser();
// when
GraphQLSchema schema = parser.parseQuery(null);
// then
Asserts.assertEquals(schema.getQueryDefinitions().size(), 0);
}
use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser 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}");
}
use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.
the class GraphQLSchemaParserTest method testStandardize4.
@Test
public void testStandardize4() {
// given
GraphQLSchemaParser parser = new GraphQLSchemaParser();
String[] queries = { "{queryName{field1 field2}}", "{queryName{field1+field2}}", "{queryName{field1,field2}}", " { queryName { field1 field2 } } ", " {\n\tqueryName {\n\t\tfield1\n\t\tfield2\n\t}\n}", "{ queryName \t{field1\t \n \t + \n \t field2} \t\n\t}", "query { queryName \t{field1\t \n \t + \n \t field2} \t\n\t}" };
int numQueries = queries.length;
GraphQLSchema[] schemas = new GraphQLSchema[numQueries];
// when
for (int i = 0; i < numQueries; ++i) {
schemas[i] = parser.parseQuery(queries[i]);
}
// then
for (int i = 0; i < numQueries; ++i) {
Asserts.assertEquals(schemas[i].getQueryDefinitions().size(), 1);
Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getName(), "queryName");
Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().size(), 2);
}
}
Aggregations