This topic describes the where parameter, part of the GraphQL API used for the Optimizely querying service, when retrieving content in Optimizely solutions.
How it works
The where parameter specifies the filter condition for the result returned by the query.
where: [{filter_condition}]
The filter_condition is defined like this:
expression: {
filter_operators: expression
}
Arguments
- {filter_condition} Defines the conditions to be met for the result to be returned. There is no limit to the number of predicates that can be included in a filter condition.
- expression A field name, a constant, a string | numeric value.
- filter_operators String operators, number operators, date operators, and bool operators.
Note: We support to use _modified extend argument to query contents (Whenever contents have been synced to our service, that contents would be marked with _modified extend field equal now())
Operators |
Description |
String operator |
Number operator |
Date Operator |
Bool operator |
eq |
Used to test equality between two expressions. |
✅ |
✅ |
✅ |
❌ |
noteq |
Used to test the condition of two expressions not being equal to each other. |
✅ |
✅ |
✅ |
❌ |
like |
Determines whether a specific character string matches a specified pattern. |
✅ |
❌ |
❌ |
❌ |
contains |
Filter fields that contains character-based data for precise or less precise matches to single words and phrases. |
✅ |
❌ |
❌ |
❌ |
gt |
Used to test the condition of one expression being greater than another. |
✅ |
✅ |
✅ |
❌ |
gte |
Used to test the condition of one expression being greater than or equal to another. |
✅ |
✅ |
✅ |
❌ |
lt |
Used to test the condition of one expression being less than another. |
✅ |
✅ |
✅ |
❌ |
lte |
Used to test the condition of one expression being less than or equal to another. |
✅ |
✅ |
✅ |
❌ |
exist |
Determines whether a specific expression exists or not. |
✅ |
✅ |
❌ |
✅ |
startsWith |
Determines whether a specific expression starts with a specific pattern. |
✅ |
❌ |
❌ |
❌ |
endsWith |
Determines whether a specific expression ends with a specific pattern. |
✅ |
❌ |
❌ |
❌ |
in |
Determines whether a specific expression is in an array. |
✅ |
✅ |
❌ |
❌ |
notIn |
Determines whether a specific expression is not in an array. |
✅ |
✅ |
❌ |
❌ |
Examples
The following examples show how to use some common filter conditions in where clause.
Using where with eq operators
{
BiographyPage(where: {
Name: {
eq: "Alan Turing"
}
}, locale: [en]) {
Name
Language {
Name
DisplayName
}
}
}
Using where with multiple filter conditions
{
BiographyPage(where: {
Name: {
eq: "Alan Turing"
}
Language: {
DisplayName: {
eq: "English"
}
}
}, locale: [en]) {
Name
Language {
Name
DisplayName
}
}
}
Note that the AND operator is the default logical operator that applies to the group of multiple filtered conditions, so the above query can be understood like this:
if (Name == "Alan Turing" AND Language.DisplayName == "English")
See Logical connectors for more information about logical operators AND, OR, and NOT.
Using where with _modified extend date argument.
The _modified field contains the date time when content was created/updated/deleted in the service. The value in _modify will not be the same as the Created/Saved value on the content.
The _modified field can be used to accomplish delta import of content from the service, for example "give me content that has been modified after (gt) 2021-09-13T04:36:14Z. Filtering by _modify field can be used together with our "cursor" functionality to accomplish good delta import of content from the service.
{
BiographyPage(where: {
_modified: {
gte: "2021-09-13T04:36:14Z"
}
}, locale: [en]) {
Name
Language {
Name
DisplayName
}
}
}
Related topics
Last updated: May 24, 2021