Skip to main content
Version: 2.0.x

Query Filters

Seaography has a rich set of built-in filters for different data types.

Operators

OperatorGraphQL FieldSupported Types
= / !=eq / neString, String-like, Integer, Float, Boolean, Json
> / >=gt / gteString, String-like, Integer, Float, Boolean
< / <=lt / lteString, String-like, Integer, Float, Boolean
case insensitive =ci_eqString
IN (..) / NOT IN (..)is_in / is_not_inString, String-like, Integer, Float, Boolean
IS NULLis_nullString, String-like, Integer, Float, Boolean
contains (LIKE '%abc%')containsString
starts_with (LIKE 'abc%')starts_withString
ends_with (LIKE '%abc')ends_withString
LIKE / NOT LIKElike / not_likeString
ILIKE (Postgres)ilikeString
BETWEEN / NOT BETWEENbetween / not_betweenString, String-like, Integer, Float
contains @> (Postgres)array_containsArray
contained <@ (Postgres)array_containedArray
overlap && (Postgres)array_overlapArray

Date, DateTime, Decimal etc are String-like.

Chaining Filters

You can specify multi fields in filters and they will be chained with AND.

You can also combine multiple filters with AND / OR:

{
film(
filters: {
or: [{ title: { contains: "LIFE" } }, { title: { contains: "WAR" } }]
}
) {
nodes {
title
}
}
}

Results in following SQL:

WHERE `film`.`title` LIKE '%LIFE%' OR `film`.`title` LIKE '%WAR%'

Examples

IS NULL

There is no IS NOT NULL, because is_null has a single bool value, with false meaning IS NOT NULL.

{
address(
filters: { postalCode: { is_null: true } }
) {
nodes {
address
postalCode
}
}
}

ILIKE

Postgres only. Requires custom config in BuilderContext:

EntityQueryFieldConfig {
use_ilike: true,
..Default::default()
}
{
customer(filters: {
firstName: {
ilike: "mario%"
}
}) {
nodes {
firstName
lastName
}
}
}

IN

{
customer(filters: {
firstName: {
is_in: ["PETER", "MARY"]
}
}) {
nodes {
firstName
lastName
}
}
}

String contains

{
address(filters: { address: { contains: "Lane" } }) {
nodes {
address
address2
postalCode
}
}
}

array_contains

Postgres only, requires with-postgres-array feature.

{
film(filters: {
title: { contains: "LIFE" }
specialFeatures: { array_contains: ["Trailers"] }
}) {
nodes {
title
specialFeatures
}
}
}

JSON =

Requires with-json feature. Let's say you've added a metadata field to the film table:

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "film")]
pub struct Model {
#[sea_orm(primary_key)]
pub film_id: i32,
pub title: String,
#[sea_orm(column_type = "JsonBinary", nullable)]
pub metadata: Option<Json>,
}

You can then filter by JSON value:

{
film(
filters: {
metadata: { eq: { imax: true, dolby: "Atmos" } }
}
) {
nodes {
filmId
title
metadata
}
}
}

MySQL / Postgres Enums

You can filter using MySQL / Postgres enums. The filter operands are typed:

input FilmFilterInput {
rating: MpaaRatingEnumFilterInput
..
}

input MpaaRatingEnumFilterInput {
eq: MpaaRatingEnum
ne: MpaaRatingEnum
..
}

enum MpaaRatingEnum {
G
PG
PG13
R
NC17
}

Such that you can do the following:

{
film(
filters: { rating: { eq: NC17 } }
pagination: { page: { page: 1, limit: 5 } }
) {
nodes {
filmId
title
rating
}
}
}