Skip to content

Issue with Map containing List #295

Closed

Description

@lyzq

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?

Activity

  1. lyzq commented on Jul 31, 2019

    @lyzq
    Author
    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;
            }
        }
    }
  2. lyzq commented on Jul 31, 2019

    @lyzq
    Author

    image
    @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?

  3. changed the title [-]a issues in map-base [/-] [+]Issue with Map containing List[/+] on Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions