Skip to content

Commit f18e69e

Browse files
authored
Merge pull request #3910 from jooby-project/3909
graphql: remove shaded/harcoded gson dependency
2 parents 8adb596 + 428e404 commit f18e69e

5 files changed

Lines changed: 30 additions & 44 deletions

File tree

modules/jooby-graphql/pom.xml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
<version>${jooby.version}</version>
1919
</dependency>
2020

21-
<dependency>
22-
<groupId>com.google.code.gson</groupId>
23-
<artifactId>gson</artifactId>
24-
<optional>true</optional>
25-
</dependency>
26-
2721
<!-- graphql -->
2822
<dependency>
2923
<groupId>com.graphql-java</groupId>
@@ -50,36 +44,4 @@
5044
<scope>test</scope>
5145
</dependency>
5246
</dependencies>
53-
54-
<build>
55-
<plugins>
56-
<plugin>
57-
<groupId>org.apache.maven.plugins</groupId>
58-
<artifactId>maven-shade-plugin</artifactId>
59-
<executions>
60-
<execution>
61-
<id>fat-jar</id>
62-
<goals>
63-
<goal>shade</goal>
64-
</goals>
65-
<phase>package</phase>
66-
<configuration>
67-
<minimizeJar>true</minimizeJar>
68-
<artifactSet>
69-
<includes>
70-
<include>com.google.code.gson:*</include>
71-
</includes>
72-
</artifactSet>
73-
<relocations>
74-
<relocation>
75-
<pattern>com.google.gson</pattern>
76-
<shadedPattern>${shaded.package}.gson</shadedPattern>
77-
</relocation>
78-
</relocations>
79-
</configuration>
80-
</execution>
81-
</executions>
82-
</plugin>
83-
</plugins>
84-
</build>
8547
</project>

modules/jooby-graphql/src/main/java/io/jooby/graphql/GraphQLModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* <p>Usage:
3232
*
3333
* <pre>{@code
34+
* // required:
35+
* install(new Jackson2Module()); // or Jackson3Module, or AvajeJsonBModule, etc.
36+
*
3437
* install(new GrapQLModule(graphQL));
3538
*
3639
* }</pre>
@@ -39,6 +42,8 @@
3942
* the route path by setting the <code>graphql.path</code> property in your application
4043
* configuration file.
4144
*
45+
* <p>NOTE: From 4.5.0 You must install a json module.
46+
*
4247
* @author edgar
4348
* @since 2.4.0
4449
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1+
/**
2+
* GraphQL module on top of https://www.graphql-java.com.
3+
*
4+
* <p>Usage:
5+
*
6+
* <pre>{@code
7+
* // required:
8+
* install(new Jackson2Module()); // or Jackson3Module, or AvajeJsonBModule, etc.
9+
*
10+
* install(new GrapQLModule(graphQL));
11+
*
12+
* }</pre>
13+
*
14+
* Module install a GET and POST route under <code>/graphql</code> path. Optionally, you can change
15+
* the route path by setting the <code>graphql.path</code> property in your application
16+
* configuration file.
17+
*
18+
* <p>NOTE: From 4.5.0 You must install a json module.
19+
*
20+
* @author edgar
21+
* @since 2.4.0
22+
*/
123
@org.jspecify.annotations.NullMarked
224
package io.jooby.graphql;

modules/jooby-graphql/src/main/java/io/jooby/internal/graphql/GraphQLHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
import java.util.Collections;
99
import java.util.Map;
1010

11-
import com.google.gson.Gson;
12-
import com.google.gson.GsonBuilder;
1311
import graphql.ExecutionInput;
1412
import graphql.ExecutionResult;
1513
import graphql.GraphQL;
1614
import io.jooby.Context;
1715
import io.jooby.Route;
1816
import io.jooby.Router;
17+
import io.jooby.json.JsonDecoder;
1918

2019
public class GraphQLHandler implements Route.Handler {
21-
private static final Gson json = new GsonBuilder().create();
22-
2320
protected GraphQL graphQL;
2421

2522
public GraphQLHandler(GraphQL graphQL) {
@@ -36,14 +33,15 @@ protected final ExecutionInput newExecutionInput(Context ctx) {
3633
if (ctx.getMethod().equals(Router.POST)) {
3734
request = ctx.body(GraphQLRequest.class);
3835
} else {
36+
var json = ctx.require(JsonDecoder.class);
3937
request = new GraphQLRequest();
4038
String query = ctx.query("query").value();
4139
String operationName = ctx.query("operationName").valueOrNull();
4240
Map<String, Object> variables =
4341
ctx.query("variables")
4442
.toOptional()
4543
.filter(string -> !string.equals("{}"))
46-
.map(str -> json.<Map<String, Object>>fromJson(str, Map.class))
44+
.map(str -> json.<Map<String, Object>>decode(str, Map.class))
4745
.orElseGet(Collections::emptyMap);
4846
request.setOperationName(operationName);
4947
request.setQuery(query);

modules/jooby-graphql/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
requires static org.jspecify;
1212
requires typesafe.config;
1313
requires com.graphqljava;
14-
requires com.google.gson;
1514
}

0 commit comments

Comments
 (0)