graphql-java-tools
graphql-java-tools copied to clipboard
Issue with Map containing List
I want to use graphql-java-tools based on Map. When Map contains fields of List type, it will report Java class is not a list or generic type information was lost: class java.lang.object. Am I using it the wrong way?
package com.sankuai.baby.dataaggregate;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.coxautodev.graphql.tools.SchemaParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class MapTest {
static ObjectMapper objectMapper = new ObjectMapper();
public static void main(String[] args) throws JsonProcessingException {
String schemaString = "type Query {\n" +
" greetOne: Greeting!\n" +
" greetTwo: Greeting!\n" +
"}\n" +
"\n" +
"type Greeting {\n" +
" name: String!\n" +
" value: String!\n" +
" key: G1\n" +
"}" +
"\n" +
"type G1{\n" +
"\ta: String\n" +
"\tb: [String]\n" +
"}";
String queryString = "{\n" +
" greetOne {\n" +
" name\n" +
" value\n" +
" key {" +
"a" +
"\nb" +
"}" +
"\n" +
" }\n" +
" greetTwo {\n" +
" value\n" +
" }\n" +
"}";
GraphQLSchema schema = SchemaParser
.newParser()
.resolvers(new QueryResolver())
.schemaString(schemaString)
.dictionary("G1",HashMap.class)
.build()
.makeExecutableSchema();
GraphQL graphQL = GraphQL.newGraphQL(schema).build();
ExecutionResult result = graphQL.execute(queryString);
System.out.println(objectMapper.writeValueAsString(result.getData()));
}
public static class QueryResolver implements GraphQLQueryResolver {
public Map<String,Object> greetOne() {
Map<String,Object> map = new HashMap<>();
map.put("value","Hello one");
map.put("name","ds one");
Map<String, Object> propertiesMap = new HashMap<>();
propertiesMap.put("a","ss");
propertiesMap.put("b",Arrays.asList("ss"));
map.put("key", propertiesMap);
return map;
}
public Map<String,Object> greetTwo() {
Map<String,Object> map = new HashMap<>();
map.put("value","Hello two");
return map;
}
}
}
@also When I skip this type check, the above code gets the result I want. So, my question is, is this type checking logic correct for List?