【问题标题】:Hasura 2.0, is there a way to use wildcards?Hasura 2.0,有没有办法使用通配符?
【发布时间】:2021-06-05 15:38:31
【问题描述】:

大家好,我在更新到 Hasura 2.0(我目前处于 Beta 1)之前查询数据的方式存在一些问题,所以在 2.0 之前,如果您向查询发送空值,它将充当通配符 * ,现在我更新到 2.0 所有查询变量都必须具有非空值,有没有办法解决这个问题?

一个小查询将作为示例:

query get_student_organization($authorId: Int, $gradeId: Int, $groupId: Int, $schoolId: Int) {
  validation: student_organization(where: {author_id: {_eq: $authorId}, escuela_id: {_eq: $schoolId}, grado_id: {_eq: $gradeId}, grupo_id: {_eq: $groupId}}) {
    id
  }
}

所以如果我只发送它

{"authorId": 5455}

我希望所有其他变量都充当通配符。 欢迎任何帮助:)

【问题讨论】:

    标签: postgresql graphql hasura


    【解决方案1】:

    您可以简单地从前端发送整个 where 对象! 这样你就可以简单地省略空变量。为此,您需要稍微调整您的查询

    query get_student_organization($wh_frontend: student_organization_bool_exp!) {
      validation: student_organization(where: $wh_frontedn) {
        id
      }
    }
    

    在变量部分,仅添加非空变量:

    {
      "where_fe": {
        "authorId": 5455
      }
    }
    

    所以这次您没有发送 schoolIdgroupIdgradeId 来满足您对通配符的需求

    【讨论】:

    • 效果很好,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多