Listing records

For each model, the lumber-graphql plugin generates a list_<modelName> query that looks like:

list_products(
page: JSON
sort: String
search: String
filter: JSON
): [products!]

So to retrieve the list of the products stored in the database, we can type the following query in the GraphQL playground:

query {
list_products {
id
title
}
}

Pagination

By default, the list_<modelName> query retrieves 10 records. The parameter page allows you to control the set of records you want to retrieve with the arguments size and number.

query {
list_products(page: { size: 3, number: 2 }) {
id
title
}
}

Sorting

You can use the parameter sort to sort the results. By default, the sorting is in ascending order. For descending order, you can use the prefix - before the field name.

query {
list_products(sort: "-created_at" ) {
id
title
created_at
}
}

The parameter search allows you to perform a global search for a String or Integer value. In the following example, we want to retrieve the list of product which contains the word "Chocolate" in one of the String fields (title in this case).

query {
list_products(search: "Chocolate") {
id
title
created_at
}
}

Filter

To perform a more precise search, you can use the parameter filter instead of search. By default, the filter is searching for a specific value. You can also use the following list of operators for a more advanced search.

query {
list_products(filter: { title: "Chocolate Muffin" }) {
id
title
created_at
}
}

Operators

Description

value

Equals

!value

Not equals

>value

Greater than (Numbers only)

<value

Lower than (Numbers only)

*value*

Contains (Strings only)

!*value*

Not contains (Strings only)

value*

Starts with (Strings only)

*value

Ends with (Strings only)

$present

Is present

$blank

Is blank

$today

Is today (Dates only)

$yesterday

Was yesterday (Dates only)

$previousXDays

Was in previous X days (must replace X by an integer) (Dates only)

$2HoursBefore

Was in previous X hours (must replace X by an integer) (Dates only)

$previousWeek

Was in previous week (Dates only)

$previousMonth

Was in previous month (Dates only)

$previousQuarter

Was in previous quarter (Dates only)

$previousYear

Was in previous year (Dates only)

$weekToDate

Is in this week to date (Dates only)

$monthToDate

Is in this month to date (Dates only)

$quarterToDate

In this quarter to date (Dates only)

$yearToDate

In this year to date (Dates only)

$past

Is in the past (Dates only)

$future

Is in the future (Dates only)

‚Äč