Search in sources :

Example 11 with GraphQLSchemaParser

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.

the class GraphQLSchemaParserTest method testStandardize3.

@Test
public void testStandardize3() {
    // given
    GraphQLSchemaParser parser = new GraphQLSchemaParser();
    String[] queries = { "{queryName}", "{ queryName}", "{queryName }", "{ queryName }", "{ \tqueryName\t}", "{ \tqueryName\t }", "{\t queryName \t}", "{ \t  \t   queryName    \t \t \t\t\t}", "{\n\tqueryName\n}", "{ queryName, }", "{ queryName+ }", "{ queryName\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");
    }
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Example 12 with GraphQLSchemaParser

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.

the class GraphQLSchemaParserTest method testStandardize2.

@Test
public void testStandardize2() {
    // given
    GraphQLSchemaParser parser = new GraphQLSchemaParser();
    String expectedQueryName = RandomUtil.randomShortAlphabetString();
    String query = "{" + expectedQueryName + "}";
    // when
    GraphQLSchema schema = parser.parseQuery(query);
    // then
    Asserts.assertEquals(schema.getQueryDefinitions().size(), 1);
    Asserts.assertEquals(schema.getQueryDefinitions().get(0).getName(), expectedQueryName);
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Example 13 with GraphQLSchemaParser

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.

the class GraphQLSchemaParserTest method testParseSchema1.

@Test
public void testParseSchema1() {
    // given
    GraphQLSchemaParser parser = new GraphQLSchemaParser();
    String[] queries = { "{q1{f1 f2{f21} f3{f31 f32}} q2}", "{q1{f1+f2{f21}+f3{f31+f32}}+q2}", "{q1{f1,f2{f21},f3{f31,f32}},q2}", "{q1{f1\tf2{f21}\tf3{f31\tf32}}\tq2}", "{q1{f1\nf2{f21}\nf3{f31\nf32}}\nq2}" };
    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(), 2);
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getName(), "q1");
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(1).getName(), "q2");
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().size(), 3);
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().get(0).getName(), "f1");
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().get(1).getName(), "f2");
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().get(2).getName(), "f3");
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().get(2).getFields().get(0).getName(), "f31");
        Asserts.assertEquals(schemas[i].getQueryDefinitions().get(0).getFields().get(2).getFields().get(1).getName(), "f32");
    }
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Example 14 with GraphQLSchemaParser

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser in project ezyhttp by youngmonkeys.

the class GraphQLSchemaParserTest method testStandardize1.

@Test
public void testStandardize1() {
    // given
    GraphQLSchemaParser parser = new GraphQLSchemaParser();
    String query = "{}";
    // when
    GraphQLSchema schema = parser.parseQuery(query);
    Throwable e = Asserts.assertThrows(() -> schema.getQueryDefinitions().get(0).getName());
    // then
    Asserts.assertEquals(schema.getQueryDefinitions().size(), 1);
    Asserts.assertEquals(IllegalArgumentException.class, e.getClass());
}
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