【问题标题】:How to filter greater than in GraphQL如何在 GraphQL 中过滤大于
【发布时间】:2018-01-22 06:52:45
【问题描述】:
type Person {
    firstName: String!,
    lastName: String!,
    age: Int!
}

如何查询所有18岁以上的人?

【问题讨论】:

    标签: graphql


    【解决方案1】:

    这可能取决于您使用的后端,但例如在 graph.cool 中你可以这样:

    query {
      allPersons(filter: {
        age_gt: 18
      }) {
        firstName
        lastName
      }
    }
    

    【讨论】:

      【解决方案2】:

      如果您使用 Prisma 作为后端,您可以使用大于运算符 (_gt),如下所示:

      query {
        persons(where: {age_gt: 18}) {
          firstName
          lastName
          age
        }
      }
      

      您还可以使用其他运算符,例如:

      • _gt(大于)
      • _lt(小于)
      • _gte(大于等于)
      • _lte(小于或等于)
      • _in(等于)
      • _not_in(不等于)

      它们兼容任何数据类型,如 Integer、Float、Double、Text、Boolean、Date 等。

      【讨论】:

        【解决方案3】:

        Hasura

        query {
          article(
            where: {rating: {_gte: 4}}
          ) {
            id
            title
            rating
          }
        }
        

        Prisma

        query {
          posts(where: {
            AND: [{
              title_in: ["My biggest Adventure", "My latest Hobbies"]
            }]
          }) {
            id
            title
          }
        }
        

        建议 不要直接/独立使用graphql,和上面的orm一起使用

        【讨论】:

          猜你喜欢
          • 2021-02-09
          • 2021-11-25
          • 1970-01-01
          • 2021-12-17
          • 2019-07-15
          • 1970-01-01
          • 2018-04-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多