Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Logical connectors

Describes logical connectors used with the GraphQL API, for the Optimizely querying service, when retrieving content in Optimizely solutions.

Construct queries with the logical (Boolean) connectors _and, _or, and _not. The precedence of _and, _or, and _not clauses is 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.

Precedence does not differ for expressions grouped in curly braces.

Examples

_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 are equivalent to the following:

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

{
  BiographyPage(where: {
    _not: [
      {
        Name: {
          eq: "Alan Turing"
        }
      },
      {
        Name: {
          eq: "Charlie Chaplin"
        }
      }
    ]
  }, locale: [en]) {
    Name
    Language {
      Name
      DisplayName
    }
  }
}

The conditions in where are equivalent to the following:

if (!(Name == "Alan Turing" OR Name == "Charlie Chaplin"))

Because of De Morgan's law, the conditions are also equivalent to the following:

if (Name != "Alan Turing" AND Name != "Charlie Chaplin"))