use of com.tvd12.ezyhttp.server.graphql.exception.GraphQLInvalidSchemeException in project ezyhttp by youngmonkeys.
the class GraphQLController method filterDataMap.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Map filterDataMap(Map dataMap, GraphQLField queryDefinition, String query) {
Map answer = new HashMap<>();
Map parentMap = null;
Stack<GraphQLField> stack = new Stack<>();
stack.add(queryDefinition);
while (stack.size() > 0) {
GraphQLField parent = stack.pop();
parentMap = parentMap == null ? answer : (Map) parentMap.get(parent.getName());
for (GraphQLField field : parent.getFields()) {
Object value = dataMap.get(field.getName());
if (value == null) {
continue;
}
if (field.getFields().isEmpty()) {
parentMap.put(field.getName(), value);
continue;
}
if (value instanceof Map) {
Object newItem = new HashMap<>();
parentMap.put(field.getName(), newItem);
stack.push(field);
} else if (value instanceof List) {
parentMap.put(field.getName(), filterDataList((List) value, field, query));
} else {
throw new GraphQLInvalidSchemeException("invalid schema: " + query + " at: " + field.getName());
}
}
}
return answer;
}
Aggregations