Skip to content
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
2 changes: 1 addition & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<smallrye-health.version>2.2.1</smallrye-health.version>
<smallrye-metrics.version>2.4.2</smallrye-metrics.version>
<smallrye-open-api.version>2.0.2</smallrye-open-api.version>
<smallrye-graphql.version>1.0.3</smallrye-graphql.version>
<smallrye-graphql.version>1.0.4</smallrye-graphql.version>
<smallrye-opentracing.version>1.3.4</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>4.3.0</smallrye-fault-tolerance.version>
<smallrye-jwt.version>2.1.2</smallrye-jwt.version>
Expand Down
6 changes: 6 additions & 0 deletions extensions/smallrye-graphql/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
<artifactId>quarkus-elytron-security-properties-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ private Class[] getGraphQLJavaClasses() {
classes.add(graphql.schema.GraphQLScalarType.class);
classes.add(graphql.schema.GraphQLSchema.class);
classes.add(graphql.schema.GraphQLTypeReference.class);
classes.add(List.class);
return classes.toArray(new Class[] {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public void testBasicPost() {

@Test
public void testBasicGet() {
String pingRequest = getPayload("{\n" +
String pingRequest = "{\n" +
" ping {\n" +
" message\n" +
" }\n" +
"}");
"}";

RestAssured.given().when()
.accept(MEDIATYPE_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

import javax.json.Json;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonReader;
import javax.json.JsonReaderFactory;
import javax.json.JsonWriter;
import javax.json.JsonWriterFactory;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ManagedContext;
Expand All @@ -29,12 +35,16 @@
public class SmallRyeGraphQLExecutionHandler implements Handler<RoutingContext> {
private static boolean allowGet = false;
private static final String QUERY = "query";
private static final String VARIABLES = "variables";
private static final String OK = "OK";
private volatile ExecutionService executionService;
private final CurrentIdentityAssociation currentIdentityAssociation;
private static final JsonBuilderFactory jsonObjectFactory = Json.createBuilderFactory(null);
private static final JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(null);
private static final JsonWriterFactory jsonWriterFactory = Json.createWriterFactory(null);

public SmallRyeGraphQLExecutionHandler(boolean allowGet, CurrentIdentityAssociation currentIdentityAssociation) {
this.allowGet = allowGet;
SmallRyeGraphQLExecutionHandler.allowGet = allowGet;
this.currentIdentityAssociation = currentIdentityAssociation;
}

Expand Down Expand Up @@ -96,13 +106,26 @@ private void handlePost(HttpServerResponse response, RoutingContext ctx) {

private void handleGet(HttpServerResponse response, RoutingContext ctx) {
if (allowGet) {
List<String> queries = ctx.queryParam(QUERY);
if (queries != null && !queries.isEmpty()) {
String graphqlGetRequest = queries.get(0);
String getResponse = doRequest(graphqlGetRequest.getBytes(StandardCharsets.UTF_8));
response.setStatusCode(200)
.setStatusMessage(OK)
.end(Buffer.buffer(getResponse));
String query = getQueryParameter(ctx, QUERY);
if (query != null && !query.isEmpty()) {
try {
String variables = getQueryParameter(ctx, VARIABLES);

JsonObjectBuilder input = jsonObjectFactory.createObjectBuilder();
input.add(QUERY, URLDecoder.decode(query, "UTF8"));
if (variables != null && !variables.isEmpty()) {
JsonObject jsonObject = toJsonObject(URLDecoder.decode(variables, "UTF8"));
input.add(VARIABLES, jsonObject);
}

String getResponse = doRequest(input.build());

response.setStatusCode(200)
.setStatusMessage(OK)
.end(Buffer.buffer(getResponse));
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException(ex);
}
} else {
response.setStatusCode(204).end();
}
Expand All @@ -111,6 +134,14 @@ private void handleGet(HttpServerResponse response, RoutingContext ctx) {
}
}

private String getQueryParameter(RoutingContext ctx, String parameterName) {
List<String> all = ctx.queryParam(parameterName);
if (all != null && !all.isEmpty()) {
return all.get(0);
}
return null;
}

private String getAllowedMethods() {
if (allowGet) {
return "GET, POST, OPTIONS";
Expand All @@ -121,23 +152,39 @@ private String getAllowedMethods() {

private String doRequest(final byte[] body) {
try (ByteArrayInputStream input = new ByteArrayInputStream(body);
final JsonReader jsonReader = Json.createReader(input)) {
final JsonReader jsonReader = jsonReaderFactory.createReader(input)) {
JsonObject jsonInput = jsonReader.readObject();
JsonObject outputJson = getExecutionService().execute(jsonInput);
if (outputJson != null) {
try (StringWriter output = new StringWriter();
final JsonWriter jsonWriter = Json.createWriter(output)) {
jsonWriter.writeObject(outputJson);
output.flush();
return output.toString();
}
}
return null;
return doRequest(jsonInput);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

private String doRequest(JsonObject jsonInput) {
JsonObject outputJson = getExecutionService().execute(jsonInput);
if (outputJson != null) {
try (StringWriter output = new StringWriter();
final JsonWriter jsonWriter = jsonWriterFactory.createWriter(output)) {
jsonWriter.writeObject(outputJson);
output.flush();
return output.toString();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
return null;
}

private static JsonObject toJsonObject(String jsonString) {
if (jsonString == null || jsonString.isEmpty()) {
return null;
}

try (JsonReader jsonReader = jsonReaderFactory.createReader(new StringReader(jsonString))) {
return jsonReader.readObject();
}
}

private ExecutionService getExecutionService() {
if (this.executionService == null) {
this.executionService = Arc.container().instance(ExecutionService.class).get();
Expand Down
3 changes: 3 additions & 0 deletions tcks/microprofile-graphql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<dependenciesToScan>
<dependency>org.eclipse.microprofile.graphql:microprofile-graphql-tck</dependency>
</dependenciesToScan>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
Expand Down
Loading