I'm newbie to GraphQL, and was wondering if someone could help me figure out what is the equivalent of below JSON into GraphQL schema:
[
{
"id": "1",
"name": "A",
"fldDef": [
{
"name": "f1",
"type": "str",
"opt": false
},
{
"name": "f2",
"type": "bool"
}]
},
{
"id": "2",
"name": "B",
"fldDef": [
{
"name": "f3",
"type": "str",
"opt": true
},
{
"name": "f4",
"type": "str",
"opt": true
}]
}
]
So far I managed to map above response to below object:
public class FldDef {
private String name, type;
private boolean opt;
// getters & setters
}
public class Product {
private String id, name;
private Map<String, FldDef> fldDef;
// getters & setters
}
Then my schema looks like below, but the problem I'm having is as a part of Product
object, I've a Map
which I would like to get the schema right for it, but I'm having difficulty getting the schema right!
type FldDef {
name: String!
type: String!
opt: Boolean!
}
type Product {
id: String!
name: String!
fldDef: FldDef! // now here I don't know what is the syntax for representing MAP, do you know how to achieve this?
}
I get below exception:
Causedby:com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException: Type java.util.Map<java.lang.String, com.grapql.research.domain.FldDef> cannot be mapped to a GraphQL type! Since GraphQL-Java deals with erased types at runtime, only non-parameterized classes can represent a GraphQL type. This allows for reverse-lookup by java class in interfaces and union types.
Note: I'm working with Java eco-system (graphql-java)