如何在GraphQl中定义Java地图?
我有一个filtermodel
是映射map< string,columnfilter> FILTERMODEL
为了过滤我的演员数据。当我尝试过滤数据时,我会从客户端获取一个filtermelodel对象。如何在GraphQl查询中定义此Java地图?
来自客户端的FILTERMODEL对象:
filterModel: {
firstname: {filterType: 'text', type: 'contains', filter: 'Tom'}, ...
}
架构:
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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GraphQl中没有地图类型。因为地图基本上包含动态键,并且它们在GraphQL期望的静态类型中的发挥作用不佳。
如果您真的不确定该数据将在该地图中使用哪种类型,则可以随时将该动态信息存储为字符串。这是我个人会做的。
因此,您的FILTERMODEL将成为
filtermodel:字符串
,该字符串将是json
对象的表示。您可以在代码中进行JSON解析以将其转换回MAP
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 aJSON
representation of the object. You can do the JSON parsing in the code to convert it back to aMap
0输入
1. SCHEMA文件
1.配置
3 bean
Note
GraphQlargumentBinder-&gt;公共对象绑定(
dataFetchingEnvironment环境,@nullable String参数名称,ResolvableType targetType)
投掷bindexception {}
无法将值绑定到地图对象,因为它使用映射名称在模式中定义,然后将DOT放置,然后将第一个密钥名称和搜索该名称搜索在BEAN中找到地图,并且目前尚未工作
0 input
1.schema file
1.configuration
3 bean
Note
GraphQlArgumentBinder-> public Object bind(
DataFetchingEnvironment environment, @Nullable String argumentName, ResolvableType targetType)
throws BindException {}
not able to bind the value to the map object because its using map name define in the schema and then put dot and then the first key name and searching of that name in the bean to find the map and its not working as of now