Filtering your data
Each content type created will have filters based on the fields it contains.
We support filtering based on the following types of fields:
- Text
- Slug
- Date
- Time
- Datetime
- Integer
- Float
- Boolean
- ID
- Reference
Available operators based on type:
| Types | Operators |
|---|---|
ID |
eq, notEq, in, notIn |
Text and Slug |
isNull, isNotNull, eq, notEq, contains, notContains, startsWith, notStartsWith, endsWith, notEndsWith, in, notIn |
Boolean |
isNull, isNotNull, eq, notEq |
Time, Date and Datetime |
isNull, isNotNull, eq, notEq, gt, gte, lt, lte, between, outside |
Integer and Float |
isNull, isNotNull, eq, notEq, gt, gte, lt, lte, between, outside, in, notIn |
Reference |
Filters generated for a reference field will be generated based on the fields of the referenced Content Type. |
Multiple<Type> |
none<TypeFilters>, any<TypeFilters>, every<TypeFilters>, where TypeFilters is one of the filters specified above. |
Additionally you can make use of the and and or conditions when filtering your data.
Filters can be applied when querying a single node or when querying a connection.
Examples
query {
post(
filters: {
id: {
eq: "7fd8b236-b925-4dd8-9484-755aaac5334d",
},
}
) {
node {
id
title
}
}
}
It will return the post with id 7fd8b236-b925-4dd8-9484-755aaac5334d
query {
allPost(
first: 5,
filters: {
title: {
contains: "Graphql",
},
featured: {
eq: true,
}
}
) {
edges {
node {
id
title
}
}
}
}
It will return the first 5 posts that contain Graphql in the title and have the field featured as true.
Multiple operators on same field
You can apply multiple operators on the same field, those would work as an and condition.
query {
post(
filters: {
title: {
contains: "John Doe",
notContains: "Jane Doe"
},
}
) {
node {
id
title
}
}
}
Using and and or conditions
You can use and and or condition to query your data, those will contain a list of filters that will be joined together through and/or conditions.
query {
allPost(
first: 5,
filters: {
or: [
{
title: {
contains: "New York"
},
},
{
title: {
contains: "Michigan"
}
}
]
}
) {
node {
id
title
}
}
}
It will return the first 5 posts that contain New York or Michigan in the title
Filtering on multiple values
For filtering on a list of values, we added the none, any and every filters. You can combine them with the operators of the field type. For example, if the field is text with multiple values, all the operators that can be applied to a text field can be specified in the none, any, and every filters.
none- will only return entries that have no matches in the list of values.any- will match entries that have at least one value in the list that matches the filter.every- will match entries that have all the values in the list matching the filter.
query {
allPost(
first: 5,
filters: {
tags: {
any: {
eq: "Guide"
}
}
}
) {
node {
id
title
}
}
}
Will return the first 5 posts having one of the tags as "Guide".