graphql - 如何在graphql查询过滤器中使用OR/AND或使大小写不敏感的过滤器?

标签 graphql gatsby

就像发问一样,我需要能够在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查询代码,则可以以某种方式自己添加它,或者请求托管或构建该代码的人以某种方式添加该功能。

关于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. ...

关于graphql - 如何在graphql查询过滤器中使用OR/AND或使大小写不敏感的过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51526079/

相关文章:

node.js - 如何在 Elasticsearch 中使用 multi_match 查询传递多个值以在多个记录中搜索多个字段

javascript - 如何将javascript变量传递给graphql查询?

javascript - 每次更新文档页时,Gatsby 是否需要重建我的整个站点?

javascript - Gatsby + Netlify-Dev Lambda 函数 - Lambda 服务器端口总是不同?

javascript - Gatsby 插件 : How Can I Take a Component as a Plug-In Option?

javascript - 框阴影过渡不适用于滚动

graphql - GraphQL 枚举类型会自动解析它们的值吗?

graphql - 我可以将 useSWR 与 apollo-client 一起使用吗?

graphql - 将 ImageSharp 作为字段添加到 MarkdownRemark 节点(不是 frontmatter)

gatsby - 如何处理 `gatsby js` 项目中的文件上传?