diff --git a/README.md b/README.md index e76d66fe1..fac2158c1 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,9 @@ Vert.x Mutiny webClient exploratory test. Also see http/vertx-web-client/README.md +### `http/graphql` +This module covers some basic scenarios around GraphQL. + ### `javaee-like-getting-started` Based on `mvn io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:create -DprojectGroupId=io.quarkus.qe -DprojectArtifactId=scenario-101-getting-started -DprojectVersion=1.0.0-SNAPSHOT -DclassName="io.quarkus.qe.hello.GreetingResource" -Dextensions=io.quarkus:quarkus-hibernate-orm,io.quarkus:quarkus-jsonb,io.quarkus:quarkus-jsonp,io.quarkus:quarkus-resteasy-jsonb,io.quarkus:quarkus-narayana-jta,io.quarkus:quarkus-elytron-security,io.quarkus:quarkus-scheduler,io.quarkus:quarkus-swagger-ui,io.quarkus:quarkus-hibernate-validator,io.quarkus:quarkus-undertow-websockets,io.quarkus:quarkus-smallrye-fault-tolerance,io.quarkus:quarkus-smallrye-metrics,io.quarkus:quarkus-smallrye-openapi,io.quarkus:quarkus-smallrye-jwt,io.quarkus:quarkus-smallrye-health,io.quarkus:quarkus-smallrye-opentracing` generated project diff --git a/http/graphql/pom.xml b/http/graphql/pom.xml new file mode 100644 index 000000000..187110e7c --- /dev/null +++ b/http/graphql/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + io.quarkus.ts.qe + parent + 1.0.0-SNAPSHOT + ../.. + + graphql + jar + Quarkus QE TS: HTTP: GraphQL + + + io.quarkus + quarkus-smallrye-graphql + + + + + deploy-to-openshift-using-extension + + + io.quarkus + quarkus-openshift + + + + + diff --git a/http/graphql/src/main/java/io/quarkus/ts/http/graphql/Person.java b/http/graphql/src/main/java/io/quarkus/ts/http/graphql/Person.java new file mode 100644 index 000000000..eebe130e2 --- /dev/null +++ b/http/graphql/src/main/java/io/quarkus/ts/http/graphql/Person.java @@ -0,0 +1,22 @@ +package io.quarkus.ts.http.graphql; + +public class Person { + public String name; + private Person friend; + + public Person(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setFriend(Person friend) { + this.friend = friend; + } + + public Person getFriend() { + return friend; + } +} diff --git a/http/graphql/src/main/java/io/quarkus/ts/http/graphql/PersonsEndpoint.java b/http/graphql/src/main/java/io/quarkus/ts/http/graphql/PersonsEndpoint.java new file mode 100644 index 000000000..3f7337fc1 --- /dev/null +++ b/http/graphql/src/main/java/io/quarkus/ts/http/graphql/PersonsEndpoint.java @@ -0,0 +1,24 @@ +package io.quarkus.ts.http.graphql; + +import org.eclipse.microprofile.graphql.Description; +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Query; + +@GraphQLApi +public class PersonsEndpoint { + private final Person[] philosophers; + + public PersonsEndpoint() { + final Person plato = new Person("Plato"); + final Person aristotle = new Person("Aristotle"); + plato.setFriend(aristotle); + aristotle.setFriend(plato); + philosophers = new Person[] { plato, aristotle }; + } + + @Query("philosophers") + @Description("Get a couple of Greek philosophers") + public Person[] getPhilosophers() { + return philosophers; + } +} diff --git a/http/graphql/src/main/resources/application.properties b/http/graphql/src/main/resources/application.properties new file mode 100644 index 000000000..7783e5668 --- /dev/null +++ b/http/graphql/src/main/resources/application.properties @@ -0,0 +1 @@ +smallrye.graphql.allowGet=true diff --git a/http/graphql/src/test/java/io/quarkus/ts/http/graphql/GraphQLIT.java b/http/graphql/src/test/java/io/quarkus/ts/http/graphql/GraphQLIT.java new file mode 100644 index 000000000..bf4e058e4 --- /dev/null +++ b/http/graphql/src/test/java/io/quarkus/ts/http/graphql/GraphQLIT.java @@ -0,0 +1,70 @@ +package io.quarkus.ts.http.graphql; + +import static io.restassured.RestAssured.given; + +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.scenarios.QuarkusScenario; +import io.restassured.path.json.JsonPath; +import io.restassured.response.Response; + +@QuarkusScenario +public class GraphQLIT { + + @Test + public void recursive() { + final String query = createQuery("philosophers{name,friend{name,friend{name}}}"); + final Response response = sendQuery(query); + final JsonPath json = response.jsonPath(); + Assertions.assertEquals("Plato", json.getString("data.philosophers[0].name")); + Assertions.assertEquals("Aristotle", json.getString("data.philosophers[0].friend.name")); + Assertions.assertEquals("Plato", json.getString("data.philosophers[0].friend.friend.name")); + } + + @Test + public void emptyGet() { + Response response = given().basePath("graphql") + .contentType("application/json") + .post(); + Assertions.assertNotEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, response.statusCode()); + Assertions.assertNotEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.statusCode()); + Assertions.assertNotEquals(HttpStatus.SC_NO_CONTENT, response.statusCode()); + Assertions.assertEquals(HttpStatus.SC_BAD_REQUEST, response.statusCode()); + } + + @Test + @Tag("QUARKUS-1537") + public void emptyPost() { + Response response = given().basePath("graphql") + .contentType("application/json") + .post(); + Assertions.assertNotEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.statusCode()); + Assertions.assertEquals(HttpStatus.SC_BAD_REQUEST, response.statusCode()); + } + + public static Response sendQuery(String query) { + return given().basePath("graphql") + .contentType("application/json") + .body(query) + .post(); + } + + public static String createQuery(String query) { + return new StringBuilder() + .append('{') + .append('"') + .append("query") + .append('"') + .append(':') + .append('"') + .append('{') + .append(query) + .append("}") + .append('"') + .append("}") + .toString(); + } +} diff --git a/http/graphql/src/test/java/io/quarkus/ts/http/graphql/OpenShiftGraphQLIT.java b/http/graphql/src/test/java/io/quarkus/ts/http/graphql/OpenShiftGraphQLIT.java new file mode 100644 index 000000000..1bcd8f2c2 --- /dev/null +++ b/http/graphql/src/test/java/io/quarkus/ts/http/graphql/OpenShiftGraphQLIT.java @@ -0,0 +1,8 @@ +package io.quarkus.ts.http.graphql; + +import io.quarkus.test.scenarios.OpenShiftScenario; + +@OpenShiftScenario +public class OpenShiftGraphQLIT extends GraphQLIT { + +} diff --git a/pom.xml b/pom.xml index e25e9c52b..de93396ef 100644 --- a/pom.xml +++ b/pom.xml @@ -376,6 +376,7 @@ http/rest-client-reactive http/servlet-undertow http/vertx-web-client + http/graphql