Logical connectors
Describes logical connectors used with the GraphQL API, for the Optimizely querying service, when retrieving content in Optimizely solutions.
You can construct queries with the logical (Boolean) connectors _and
, _or
, and _not
. The precedence of connectors and
, _or
, and _not
clauses are from left to right. This lets you group one or more fields, where each member uses the Boolean connector. By default, with no Boolean connector, the clauses are conjunctions, an implicit _and
.
There is no difference in precedence for expressions grouped in curly braces.
Examples
_and
clause nested within an _or
clause:
_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")
not
clause:
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"))
Updated 4 months ago