我有一个filterModel
,它是一个Map Map<String, ColumnFilter> filterModel
,以便过滤我的Actor数据。当我试图过滤我的数据时,我从客户端获得一个filterModel对象。如何在graphql查询中定义此Java Map?
来自客户端的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
}
2条答案
按热度按时间hyrbngr71#
GraphQL中没有map类型。因为map基本上包含动态键和,所以它们不能很好地适应GraphQL所期望的静态类型。
如果您真的不确定Map中的数据将是什么类型,您可以始终将动态信息存储为String。这是我个人会做的事情。
所以你的filterModel将变成
filterModel:String
,而这个字符串将是对象的JSON
表示。您可以在代码中执行JSON解析,将其转换回Map
fnx2tebb2#
0输入
1.模式文件
1.configuration
3豆
注意事项
GraphQlArgumentBinder-> public Object bind(DataFetchingEnvironment environment,@Nullable String argumentName,ResolvableType targetType)抛出BindException {}无法将值绑定到map对象,因为它使用了在模式中定义的map名称,然后将点和第一个键名放在bean中搜索该名称以找到map,并且它目前无法工作