How to filter greater than in GraphQL

type Person {
    firstName: String!,
    lastName: String!,
    age: Int!
}

How to query all people what are older than 18?


It probably depends on the backend you are using but e.g. in graph.cool you could something like this:

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

If you are using Prisma as backend, you could use the greater than operator (_gt), like so:

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

You can also use other operators like:

  • _gt (greater than)
  • _lt (less than)
  • _gte (greater than or equal to)
  • _lte (less than or equal to)
  • _in (equal to)
  • _not_in (not equal to)

They are compatible with any data types like Integer, Float, Double, Text, Boolean, Date, etc.


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
  }
}

Advice Do not use graphql directly/independently ,use it with above orm's