Search in sources :

Example 6 with GraphQLSchema

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchema 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 7 with GraphQLSchema

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchema 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 8 with GraphQLSchema

use of com.tvd12.ezyhttp.server.graphql.GraphQLSchema 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)

Example 9 with GraphQLSchema

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

the class GraphQLSchemaTest method test.

@Test
public void test() {
    // given
    GraphQLSchema.Builder builder = GraphQLSchema.builder();
    // when
    GraphQLSchema schema = builder.build();
    // then
    Asserts.assertEquals(schema.getQueryDefinitions(), Collections.emptyList());
}
Also used : GraphQLSchema(com.tvd12.ezyhttp.server.graphql.GraphQLSchema) Test(org.testng.annotations.Test)

Aggregations

GraphQLSchema (com.tvd12.ezyhttp.server.graphql.GraphQLSchema)9 Test (org.testng.annotations.Test)9 GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)8