Query

query syntax

query [<op-name>] {
  object [([argument])]{
    object-fields
  }
}

Example query:

query {
  user(
    where: { name: { _eq: "Amirmasoud" } }
  ) {
    id
    name
    created_at
  }
}

query_by_pk syntax

Return one model object (if found any) using defined PK defined for model using getKeyName which gets primaryKey property on the model. It's usually id. The input argument is also limited to this key.

query [<op-name>] {
  <query-field-name> (
    column1: value1
  )
  <object-fields>
}

Example:

query {
  user_by_pk(
    id: 32
  ) {
    name
    email
    created_at
  }
}

Simple Object

Example:

query {
  user {
    id
    name
    tags {
      id
      title
    }
    categories_aggregate {
      aggregate {
        count
      }
      nodes {
        title
      }
    }
  }
}

Aggregate object

user_aggregate {
  aggregate {
    count
    sum {
      ...aggregateOnThisFields
    }
    avg {
      ...aggregateOnThisFields
    }
    max {
      ...aggregateOnThisFields
    }
    min {
      ...aggregateOnThisFields
    }
  }
  nodes {
    id
    name
    tags {
      title
    }
    categories_aggregate {
      aggregate {
        count
      }
      nodes {
        title
      }
    }
  }
}

fragment aggregateOnThisFields on UserResultAggregateType {
  id
}

Available aggregate functions: min, max, sum, avg and, count.

Arguments

Distinct

Example:

query {
  user(distinct: true) {
    id
    name
    email
    created_at
  }
}

:warning: For PostgreSQL users: There is no distinct_on support at the moment.

Where

Example:

query {
  user(where: {email: {_like: "%example.com"}}) {
    name
    tags {
      title
    }
  }
}

_and

Queries are executed with the and operator by default.

Example:

query {
  user(
    where: {
      _and: {
        name: { _nlike: "%pattern%" },
        updated_at: { _year: "2020" }
      }
    }
  ) {
    id
    name
    email
    updated_at
  }
}

_or

Example:

query {
  user(
    where: {
      _or: {
        name: { _nlike: "%pattern%" },
        updated_at: { _year: "2021" }
      }
    }
  ) {
    id
    name
    email
    updated_at
  }
}

_not

Example:

query {
  user(
    where: {
      _not: {
        name: { _nlike: "%pattern%" },
        updated_at: { _year: "2020" }
      }
    }
  ) {
    id
    name
    email
    updated_at
  }
}

Operators

OperatorEquivalentNote
_eq=
_neq<>,!=
_gt>
_lt<
_gte>=
_lte<=
_inIN
_ninNOT IN
_likeLIKE
_nlikeNOT LIKE
_ilikeILIKEPostgreSQL only
nilikeNOT ILIKEPostgreSQL only
_similarSIMILAR TO
_nsimilarNOT SIMILAR TO
_is_nullIS NULL

:warning: JSON operators are not yet supported.

Order

Example:

query {
  user(
    order_by: { id: asc }
  ) {
    id
    name
  }
}

Available orders: asc, desc

Pagination

Example #1:

query {
  user(
    limit: 5
    offset: 10
  ) {
    id
    name
  }
}

Example #2:

query {
  user(
    take: 5
    skip: 10
  ) {
    id
    name
  }
}