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
38 changes: 0 additions & 38 deletions modules/jooby-graphql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
<version>${jooby.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<optional>true</optional>
</dependency>

<!-- graphql -->
<dependency>
<groupId>com.graphql-java</groupId>
Expand All @@ -50,36 +44,4 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>fat-jar</id>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>com.google.code.gson:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>${shaded.package}.gson</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* <p>Usage:
*
* <pre>{@code
* // required:
* install(new Jackson2Module()); // or Jackson3Module, or AvajeJsonBModule, etc.
*
* install(new GrapQLModule(graphQL));
*
* }</pre>
Expand All @@ -39,6 +42,8 @@
* the route path by setting the <code>graphql.path</code> property in your application
* configuration file.
*
* <p>NOTE: From 4.5.0 You must install a json module.
*
* @author edgar
* @since 2.4.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
/**
* GraphQL module on top of https://www.graphql-java.com.
*
* <p>Usage:
*
* <pre>{@code
* // required:
* install(new Jackson2Module()); // or Jackson3Module, or AvajeJsonBModule, etc.
*
* install(new GrapQLModule(graphQL));
*
* }</pre>
*
* Module install a GET and POST route under <code>/graphql</code> path. Optionally, you can change
* the route path by setting the <code>graphql.path</code> property in your application
* configuration file.
*
* <p>NOTE: From 4.5.0 You must install a json module.
*
* @author edgar
* @since 2.4.0
*/
@org.jspecify.annotations.NullMarked
package io.jooby.graphql;
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
import java.util.Collections;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import io.jooby.Context;
import io.jooby.Route;
import io.jooby.Router;
import io.jooby.json.JsonDecoder;

public class GraphQLHandler implements Route.Handler {
private static final Gson json = new GsonBuilder().create();

protected GraphQL graphQL;

public GraphQLHandler(GraphQL graphQL) {
Expand All @@ -36,14 +33,15 @@ protected final ExecutionInput newExecutionInput(Context ctx) {
if (ctx.getMethod().equals(Router.POST)) {
request = ctx.body(GraphQLRequest.class);
} else {
var json = ctx.require(JsonDecoder.class);
request = new GraphQLRequest();
String query = ctx.query("query").value();
String operationName = ctx.query("operationName").valueOrNull();
Map<String, Object> variables =
ctx.query("variables")
.toOptional()
.filter(string -> !string.equals("{}"))
.map(str -> json.<Map<String, Object>>fromJson(str, Map.class))
.map(str -> json.<Map<String, Object>>decode(str, Map.class))
.orElseGet(Collections::emptyMap);
request.setOperationName(operationName);
request.setQuery(query);
Expand Down
1 change: 0 additions & 1 deletion modules/jooby-graphql/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
requires static org.jspecify;
requires typesafe.config;
requires com.graphqljava;
requires com.google.gson;
}
Loading