PostGraphile中的筛选不起作用

huangapple go评论55阅读模式
英文:

Or filtering with PostGraphile not working

问题

我尝试在一个查询中使用 OR 和筛选器来搜索多个字段。

query SearchQuery($searchTerm: String) {
  allArtists(
    filter: {
      surname: { includesInsensitive: $searchTerm },
      or: { firstname: { includesInsensitive: $searchTerm } }
    }
  ) {
    edges {
      node {
        firstname
        surname
      }
    }
  }
}

surnamefirstname 分别查询时会返回结果,但当与 OR 结合时不会返回结果。

是否可能搜索多个字段?

英文:

I am trying to search multiple fields in one query with the use of the OR and filter.

query SearchQuery($searchTerm: String) {
  allArtists(
    filter: {surname: {includesInsensitive: $searchTerm}, or: {firstname: {includesInsensitive:  $searchTerm}}}
  ) {
    edges {
      node {
        firstname
        surname
      }
    }
  }

Both surname and firstname will return results if done separately, however when combining with a OR it will return no results.

Is it possible to search multiple fields?

答案1

得分: 1

filter操作将所有选项与AND组合。or选项接受一个筛选器列表,并将它们与OR组合。由于您只想要OR条件,您需要在OR列表内提供您的选项:

query SearchQuery($searchTerm: String) {
  allArtists(
    filter: {or: [
      {surname: {includesInsensitive: $searchTerm}},
      {firstname: {includesInsensitive:  $searchTerm}}
    ]}
  ) {
    edges {
      node {
        firstname
        surname
      }
    }
  }
}
英文:

The filter takes all options and combines with AND. The or option takes a list of filters and combines them with OR. Since you only want the OR condition you need to supply your options inside the OR list:

query SearchQuery($searchTerm: String) {
  allArtists(
    filter: {or: [
      {surname: {includesInsensitive: $searchTerm}},
      {firstname: {includesInsensitive:  $searchTerm}}
    ]}

  ) {
    edges {
      node {
        firstname
        surname
      }
    }
  }
}

huangapple
  • 本文由 发表于 2023年3月4日 06:21:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定