就像发问一样,我需要能够在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 functiongetCaseByStatus
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/