如何在 graphql 查询过滤器中使用 OR / AND 或制作不区分大小写的过滤器?

How to use OR / AND in graphql query filter or make a case insensitive filter?

就像 post 问一样,我需要能够搜索 3 种可能的情况。我需要全部大写、小写或普通大小写。

如果这不可能,是否有办法改为执行不区分大小写的过滤器?

  allMarkdownRemark(filter: { brand: { eq: $normalBrand } }) { //==> Need more here
        edges {
            node {
                webImages {
                    url
                }
            }
        }
    }

我发现有些人这样做:

filter: { OR: [
  {brand: { eq: $normalBrand }}, 
  {brand: { eq: $normalBrand2 }}, 
  {brand: { eq: $normalBrand3 }}
]}

但是对我不起作用

目前 graphql 本身没有任何内置的东西使用不区分大小写的搜索,它完全基于 graphql 服务器 运行 的任何库,如果选择添加对此的支持。如果您可以修改 graphql 查询代码,您可以以某种方式在自己中添加它,或者请求 hosting/building 以某种方式添加该功能。

关于 OR,我怀疑我能说得比 https://github.com/graphql/graphql-js/issues/585#issuecomment-262402544

GraphQL doesn't have support for AND/OR operators for exactly the reason you mentioned at the top of your issue: it does not map to any kind of storage. I think to properly understand why it does not have these requires a shift in mental models. We think of GraphQL as more similar to RPC languages than database languages.

To help understand the mental model shift, it's useful to think about fields and arguments like function calls in programming languages. So suppose we ask a similar question of javascript: Why can't you type: getCaseByStatus("open" OR "closed")? The answer, I would assume, is because JavaScript does not know what OR means in this context. Should the values "open" and "closed" be combined in some way to produce another value? Should the execution of the function getCaseByStatus change in some way? JavaScript can't be sure - because the concept of field-based filtering is not part of JavaScript's semantics. ...

正则表达式有效吗?像

  allMarkdownRemark(filter: { brand: { 
     regex: "/($normalBrand)|($normalBrand2)|($normalBrand3)/" 
  } }) { 
        edges {
            node {
                webImages {
                    url
                }
            }
        }
    }

尝试用小写过滤 'or'

过滤器:{ 或:[{brand: { eq: $normalBrand }}, {brand: { eq: $normalBrand2 }},{brand: { eq: $normalBrand3 }}]}