diff --git a/graphql/graphql-java/pom.xml b/graphql/graphql-java/pom.xml index f2733bf671..5808dd17fb 100644 --- a/graphql/graphql-java/pom.xml +++ b/graphql/graphql-java/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../../ + ../../pom.xml @@ -36,51 +36,15 @@ graphql-java-annotations ${graphql-java-annotations.version} - - io.ratpack - ratpack-core - ${ratpack-core.version} - - - com.github.americanexpress.nodes - nodes - 0.5.0 - - - com.graphql-java - graphql-java - 9.2 - com.graphql-java graphql-java-tools - 5.2.4 + ${graphql-java-tools.version} com.graphql-java graphql-java-servlet - 6.1.3 - - - javax.servlet - javax.servlet-api - 3.0.1 - provided - - - org.apache.commons - commons-lang3 - 3.12.0 - - - org.mock-server - mockserver-netty - 5.11.2 - - - org.mock-server - mockserver-client-java - 5.11.2 + ${graphql-java-servlet.version} com.graphql-java-generator @@ -88,15 +52,47 @@ ${graphql.java.generator.version} - org.junit.jupiter - junit-jupiter-engine - 5.8.2 + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + provided + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + io.ratpack + ratpack-core + ${ratpack-core.version} + + + com.github.americanexpress.nodes + nodes + ${nodes.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + + org.mock-server + mockserver-netty + ${mockserver-netty.version} test - org.assertj - assertj-core - 3.22.0 + org.mock-server + mockserver-client-java + ${mockserver-client-java.version} test @@ -115,11 +111,11 @@ org.eclipse.jetty jetty-maven-plugin - 10.0.7 + ${jetty-maven-plugin.version} maven-war-plugin - 3.1.0 + ${maven-war-plugin.version} com.graphql-java-generator @@ -143,12 +139,21 @@ + 5.2.4 + 6.1.3 3.0.3 - 1.4.6 - 3.1 + 1.18 + 1.9.0 + 0.5.0 + 4.5.13 + + 5.13.2 + 5.13.2 + + 10.0.7 + 1.8 1.8 - 1.18 \ No newline at end of file diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphql/handler/UserHandler.java b/graphql/graphql-java/src/main/java/com/baeldung/graphql/handler/UserHandler.java index a6d474a70d..eb7cf021c6 100644 --- a/graphql/graphql-java/src/main/java/com/baeldung/graphql/handler/UserHandler.java +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphql/handler/UserHandler.java @@ -19,24 +19,27 @@ import com.baeldung.graphql.utils.SchemaUtils; import static ratpack.jackson.Jackson.json; public class UserHandler implements Handler { + private static final Logger LOGGER = Logger.getLogger(UserHandler.class.getSimpleName()); - private GraphQL graphql; - private static List users = new ArrayList<>(); + + private static final List USERS = new ArrayList<>(); + + private final GraphQL graphql; public UserHandler() throws Exception { - graphql = new GraphQL(new UserSchema().getSchema()); + graphql = GraphQL.newGraphQL(new UserSchema().getSchema()).build(); } @Override - public void handle(Context context) throws Exception { + public void handle(Context context) { context.parse(Map.class) .then(payload -> { Map parameters = (Map) payload.get("parameters"); ExecutionResult executionResult = graphql.execute(payload.get(SchemaUtils.QUERY) .toString(), null, this, parameters); + Map result = new LinkedHashMap<>(); - if (executionResult.getErrors() - .isEmpty()) { + if (executionResult.getErrors().isEmpty()) { result.put(SchemaUtils.DATA, executionResult.getData()); } else { result.put(SchemaUtils.ERRORS, executionResult.getErrors()); @@ -46,8 +49,8 @@ public class UserHandler implements Handler { }); } - public static List getUsers() { - return users; + public List getUsers() { + return USERS; } public static List getUsers(DataFetchingEnvironment env) {