filtering
graphql

Filtering

Every table query accepts a where argument with rich filter operators.

Operators

OperatorSQL equivalentExample
eq= valuerating: { eq: "PG" }
neq!= valuerating: { neq: "R" }
gt> valuelength: { gt: 90 }
gte>= valuerental_rate: { gte: 2.99 }
lt< valuelength: { lt: 60 }
lte<= valuerental_rate: { lte: 0.99 }
inIN (...)rating: { in: ["PG", "G"] }
notInNOT IN (...)rating: { notIn: ["NC-17"] }
isNullIS NULLdescription: { isNull: true }
isNotNullIS NOT NULLdescription: { isNotNull: true }
containsILIKE '%val%'title: { contains: "academy" }
startsWithILIKE 'val%'title: { startsWith: "A" }
endsWithILIKE '%val'title: { endsWith: "er" }
likeLIKE 'val'title: { like: "ACE%" }
ilikeILIKE 'val'title: { ilike: "%ace%" }

Examples

Multiple conditions (AND)

{
  film(where: {
    rating: { eq: "PG" }
    length: { gte: 60, lte: 120 }
    rental_rate: { lte: 2.99 }
  }) {
    title
    length
    rental_rate
  }
}

Filter with relationships

{
  rental(where: {
    return_date: { isNull: true }
  }) {
    rental_id
    customer {
      first_name
      last_name
      email
    }
    inventory {
      film {
        title
      }
    }
  }
}

Text search

{
  film(where: { title: { ilike: "%dinosaur%" } }) {
    title
    description
  }
}

IN filter

{
  film(where: { rating: { in: ["PG", "G"] }, length: { lt: 90 } }) {
    title
    rating
    length
  }
}

Sorting and Pagination

Combine filters with ordering and pagination:

{
  film(
    where: { rental_rate: { lte: 0.99 } }
    orderBy: { length: DESC }
    limit: 10
    offset: 0
  ) {
    title
    length
    rental_rate
  }
}

Cursor Pagination

{
  filmConnection(first: 10, after: "cursor_value") {
    edges {
      node { film_id title rental_rate }
      cursor
    }
    pageInfo { hasNextPage endCursor }
    totalCount
  }
}