【问题标题】:how to make a case-insensitive graphql query?如何进行不区分大小写的graphql查询?
【发布时间】:2019-05-21 13:24:54
【问题描述】:

使用 GraphQL 获取和解析配置文件,有时文件名是podfile,有时是Podfile,所以我想知道如何进行不区分大小写的查询?

现在我只能查询repository->object: podfile和Podfile,但是如果文件名是podFILE,又不行。

query($org_name: String!, $resp_name: String!)
                {
                repository(owner: $org_name name: $resp_name){
                          object: object(expression: "%s:proj.ios_mac/podfile"){
                                                              ... on Blob{
                                                                          text
                                                                          }
                                                              }
                          ios_object_1: object(expression: "%s:proj.ios_mac/Podfile"){
                                                              ... on Blob{
                                                                          text
                                                                          }
                                                              }
                          }
                }

REF:https://github.community/t5/How-to-use-Git-and-GitHub/graphql-api-resource-query-is-case-sensitive/m-p/6003

【问题讨论】:

    标签: graphql


    【解决方案1】:
    _similar: "%key%" performs Case sensitive query
    _ilike:   "%key%" performs case insensitive query
    

    例如:下面的查询将返回名称包含 iphone 的所有设备。如果名称包含“iPhone”,即查询区分大小写,则返回对象失败。

    query MyQuery {
      devices: devices(where: {name: { _similar: "%iphone%"}}) {
        name
     }
    }
    

    以下查询将返回名称包含“iphone”、“iPhone”的所有对象。即不区分大小写

    query MyQuery {
      devices: devices(where: {name: { _ilike: "%iphone%"}}) {
        name
     }
    }
    

    【讨论】:

    • 请补充一点,有助于理解清楚。
    • @MobileEvangelist 已详细阐述
    • _喜欢这个答案 ;-)
    【解决方案2】:

    使用_ilike 运算符使查询不区分大小写。

    query MyQuery {
      heroes(where: {name: {_ilike: "%baTmaN%"}}) {name, movie }
    }
    

    来源和文档:https://github.com/hasura/graphql-engine/issues/1516

    【讨论】:

      【解决方案3】:

      根据spec,GraphQL 中的名称区分大小写。名称包括字段名、类型名、变量名等。

      所以,总之是不可能的。

      【讨论】:

      猜你喜欢
      • 2018-06-26
      • 2011-10-23
      • 2011-10-29
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      相关资源
      最近更新 更多