filtering
graphql
Filtering
Every table query accepts a where argument with rich filter operators.
Operators
| Operator | SQL equivalent | Example |
|---|---|---|
eq | = value | rating: { eq: "PG" } |
neq | != value | rating: { neq: "R" } |
gt | > value | length: { gt: 90 } |
gte | >= value | rental_rate: { gte: 2.99 } |
lt | < value | length: { lt: 60 } |
lte | <= value | rental_rate: { lte: 0.99 } |
in | IN (...) | rating: { in: ["PG", "G"] } |
notIn | NOT IN (...) | rating: { notIn: ["NC-17"] } |
isNull | IS NULL | description: { isNull: true } |
isNotNull | IS NOT NULL | description: { isNotNull: true } |
contains | ILIKE '%val%' | title: { contains: "academy" } |
startsWith | ILIKE 'val%' | title: { startsWith: "A" } |
endsWith | ILIKE '%val' | title: { endsWith: "er" } |
like | LIKE 'val' | title: { like: "ACE%" } |
ilike | ILIKE '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
}
}