Skip to content

Commit 735fe7b

Browse files
committed
Problem: mutations don't work
Can't parse variables passed as a string Solution: adjust parsing of the request
1 parent 0fd21c4 commit 735fe7b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
package graphql.servlet;
1616

17-
import com.fasterxml.jackson.annotation.JsonRawValue;
17+
import com.fasterxml.jackson.annotation.JsonProperty;
1818
import com.fasterxml.jackson.core.type.TypeReference;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import com.google.common.io.CharStreams;
@@ -165,10 +165,20 @@ public String executeQuery(String query) {
165165
public static class Request {
166166
@Getter @Setter
167167
private String query;
168-
@Getter @Setter
168+
@Getter
169169
private Map<String, Object> variables = new HashMap<>();
170170
@Getter @Setter
171171
private String operationName;
172+
173+
@SneakyThrows @JsonProperty("variables")
174+
public String getVariablesAsString() {
175+
return new ObjectMapper().writeValueAsString(variables);
176+
}
177+
178+
@SneakyThrows
179+
public void setVariables(String variables) {
180+
this.variables = new ObjectMapper().readValue(variables, new TypeReference<Map<String, Object>>() {});
181+
}
172182
}
173183

174184
@Override

0 commit comments

Comments
 (0)