Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.2] Graphql coverage #461

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions http/graphql/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus.ts.qe</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>graphql</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: HTTP: GraphQL</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-graphql</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>deploy-to-openshift-using-extension</id>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-openshift</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
22 changes: 22 additions & 0 deletions http/graphql/src/main/java/io/quarkus/ts/http/graphql/Person.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions http/graphql/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smallrye.graphql.allowGet=true
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.ts.http.graphql;

import io.quarkus.test.scenarios.OpenShiftScenario;

@OpenShiftScenario
public class OpenShiftGraphQLIT extends GraphQLIT {

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
<module>http/rest-client-reactive</module>
<module>http/servlet-undertow</module>
<module>http/vertx-web-client</module>
<module>http/graphql</module>
</modules>
</profile>
<profile>
Expand Down