I have a filterModel
which is a Map Map<String, ColumnFilter> filterModel
in order to filter my Actor data. I get an filterModel Object from the client when I try to filter my data. How do I define this Java Map in my graphql Query?
filterModel Object from client:
filterModel: {
firstname: {filterType: 'text', type: 'contains', filter: 'Tom'}, ...
}
schema:
type Actor {
actorId: ID!,
firstName: String,
lastName: String,
}
type Query {
rows(
filterModel: [filterModel]
): [Actor]
}
input filterModel {
key: String,
value: ColumnFilter
}
input ColumnFilter {
filterType: String,
type: String,
filter: String
}
CodePudding user response:
There is no map type in GraphQL. Because maps are basically containing dynamic keys and, they do not play well into the static types that GraphQL is expecting.
If you are really unsure of what type the data is going to be in that map, you can always store that dynamic information as a String. This is something I personally would do.
So your filterModel would become
filterModel:String
and that string would be a JSON
representation of the object. You can do the JSON parsing in the code to convert it back to a Map