Skip to content

Commit

Permalink
Change to handle variables sent as an empty string to graphql endpoint
Browse files Browse the repository at this point in the history
Fix #2367
  • Loading branch information
johannilsson committed Nov 22, 2016
1 parent 60faa02 commit efd08b3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/org/opentripplanner/index/IndexAPI.java
Expand Up @@ -585,20 +585,24 @@ public Response getStopCluster (@PathParam("clusterId") String clusterIdString)
@POST
@Path("/graphql")
@Consumes(MediaType.APPLICATION_JSON)
public Response getGraphQL (HashMap<String, Object> query) {
public Response getGraphQL (HashMap<String, Object> queryParameters) {
String query = (String) queryParameters.get("query");
Object queryVariables = queryParameters.getOrDefault("variables", null);
String operationName = (String) queryParameters.getOrDefault("operationName", null);
Map<String, Object> variables;
if (query.get("variables") instanceof Map) {
variables = (Map) query.get("variables");
} else {
if (queryVariables instanceof Map) {
variables = (Map) queryVariables;
} else if (queryVariables instanceof String && !((String) queryVariables).isEmpty()) {
try {
variables = deserializer.readValue((String) query.get("variables"), Map.class);
variables = deserializer.readValue((String) queryVariables, Map.class);
} catch (IOException e) {
LOG.error("Variables must be a valid json object");
return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
}
} else {
variables = new HashMap<>();
}
String operationName = (String) query.getOrDefault("operationName", null);
return index.getGraphQLResponse((String) query.get("query"), variables, operationName);
return index.getGraphQLResponse(query, variables, operationName);
}

@POST
Expand Down

0 comments on commit efd08b3

Please sign in to comment.