我们可以编写GraphQL查询来获取基于谓词(条件)的数据吗



我需要用一些类似的谓词编写graphql查询

Select * from User Where loginId like "abc%"

在GraphQL:中

{
getWithPredicate(clazz : String, predicates : Predicates){
loginId
enabled
accountLocked
accountExpired
accountExpireBy
createdBy
}
}

如果graphql中有任何默认实现可用,请提出建议。

提前谢谢。

这是可能的。我曾经写过这样一个查询。我需要使用一些搜索词来搜索数据库。

query ($title: String!, $company: String!, $city: String!, $investor: String!) {
jobs(
where: {
and: [
{ title: { ilike: $title } },
{ company: { name: { ilike: $company } } },
{ city: { ilike: $city } },
{company: {company_investors:{investor:{name: {ilike: $investor}}}}}

]
}
) {
id
title
city
company {
name
id
company_investors {
investor {
name
id
}
}
}
}
}
# glob: I want all the titles that contain the word 'History'.
# The wildcard * stands for any non-empty string.
example_glob: allMarkdownRemark(
filter: { frontmatter: { title: { glob: "*History*" } } }
) {
edges {
node {
frontmatter {
title
}
}
}
}

可能的操作员的完整列表

  • eq:等于的缩写,必须与给定的数据完全匹配

  • ne:(的缩写(不等于,必须与给定的数据不同

  • regex:正则表达式的缩写,必须与给定的模式匹配

  • glob:全局的缩写,允许使用通配符*作为任何非空字符串的占位符

  • in:是数组中的缩写,必须是数组的元素

  • nin:的缩写,不在数组中,必须不是数组的元素

  • gt:大于的缩写,必须大于给定值

  • gte:大于或等于的缩写,必须大于或等于至给定值

  • lt:小于的缩写,必须小于给定值

  • lte:小于或等于的缩写,必须小于或等于给定值

  • elemMatch:元素匹配的缩写,这表示您are筛选将返回一个元素数组,您可以在该数组上使用以前的操作员应用过滤器

最新更新