This topic describes logical connectors used with the GraphQL API, for the Optimizely querying service, when retrieving content in Optimizely solutions.
How it works
Queries can be constructed with the logical (Boolean) connectors AND, OR, and NOT. The precedence of connectors AND, OR, and NOT clauses is from left to right. This allows for grouping of 1 or more fields, where each member in the group are using the Boolean connector.
There is no difference in precedence for expressions grouped in curly braces.
Example: An AND clause nested within an OR clause:
{
BiographyPage(
where: {
OR: [
{Name: {eq: "Alan Turing"}}
{
AND: [
{FamousQuote: {contains: "What am I in the eyes of most people"}}
{FamousQuote: {contains: "That is my ambition"}}
]
}
{Name: {eq: "Charlie Chaplin"}}
]
}
locale: [en]
) {
Name
FamousQuote
}
}
The conditions expressed in where is equivalent to:
if (Name == "Alan Turing" OR (FamousQuote.Contains("What am I in the eyes of most people") AND FamousQuote.Contains("That is my ambition")) OR Name == "Charlie Chaplin")
Example with NOT clause:
{
BiographyPage(where: {
NOT: [
{
Name: {
eq: "Alan Turing"
}
},
{
Name: {
eq: "Charlie Chaplin"
}
}
]
}, locale: [en]) {
Name
Language {
Name
DisplayName
}
}
}
The conditions in where is equivalent to:
if (!(Name == "Alan Turing" OR Name == "Charlie Chaplin"))
And because of De Morgan's Law also equivalent to:
if (Name != "Alan Turing" AND Name != "Charlie Chaplin"))
Related topics
Last updated: May 20, 2021