Step 5 of 11 (45% complete)

GraphQl Queries Updates

Content variations

Optimizely Graph supports querying for Optimizely Content Management System (CMS) (SaaS) content variations. This enables Graph clients to retrieve content tailored for A/B testing, personalization, localization, or campaign-based experiences, depending on user context.

Default behavior

By default, GraphQL queries do not include variations. If you want to get variation content (and preview variation), you must specify it in the query using variation: { include: ALL}, or specify the variation key.

Query variations

Get all variations of a content item

To return all content variations (including the original), add a filter or field selector to include the variation property. This will be particularly useful for previews where we want to get all versions of a variation and then select the one that matches based on the key and version provided in the search parameters.

query GetAllVariations {
  _Content(variation: { include: ALL, includeOriginal: true }) {
    items {
      _metadata {
        key
        displayName
      }
    }
  }
}

Query specific variations

To obtain a specific variation, filter by the ‘value’ field: This will be particularly useful when the feature exp SDK returns the variation to be displayed for a specific user, in which case we will use this query.

query GetSomeVariations($variations: [String], $includeDefaultContent: Boolean = true) {
  _Content(variation: { include: SOME, value: $variations, includeOriginal: $includeDefaultContent }) {
    items {
      _metadata {
        key
        displayName
      }
    }
  }
}

Query only default content (no variations)

Use this to fetch only the original content that has no variation value. When we don't include any variation, this the default behavior for now.

query GetOnlyDefaultContent {
  _Content(variation: { include: NONE, includeOriginal: true }) {
    items {
      _metadata {
        key
        displayName
      }
    }
  }
}

Read more about Content Variations in Optimizely Graph here

Have questions? I'm here to help!

Contact Me