Search in sources :

Example 6 with GraphQLSchemaParser

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);
}
Also used : GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) List(java.util.List)

Example 7 with GraphQLSchemaParser

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");
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Example 8 with GraphQLSchemaParser

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);
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Example 9 with GraphQLSchemaParser

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

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);
    }
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Aggregations

GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)13 Test (org.testng.annotations.Test)13 GraphQLSchema (com.tvd12.ezyhttp.server.graphql.GraphQLSchema)8 GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)5 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)4 GraphQLRequest (com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest)3 HttpNotFoundException (com.tvd12.ezyhttp.core.exception.HttpNotFoundException)1 GraphQLInvalidSchemeException (com.tvd12.ezyhttp.server.graphql.exception.GraphQLInvalidSchemeException)1 List (java.util.List)1