Nov 15, 2024
Optimizely Graph is a set of APIs that teams can use to easily fetch data and content from multiple sources and deliver it anywhere they need. Graph leverages GraphQL to enhance the capabilities of Optimizely CMS. Teams can also use it to sync data from other Optimizely products and search and manipulate content using the GraphQL standard.
Optimizely Graph enables businesses to seamlessly deliver the right content to the right channels, improving personalization and enhancing the customer experience. In this blog, we’ll explore Optimizely Graph and the benefits it can provide for anyone using the Optimizely DXP.
Understanding GraphQL
Before exploring Optimizely Graph, we’ll explain GraphQL and its differences from the more common API standard REST.
Initially developed by Facebook (now Meta) in 2012, before being open-sourced in 2015, GraphQL is a data querying and manipulation language for APIs. Developers use GraphQL as an alternative to REST since it allows them to specify the exact data needed from an API using an approach known as declarative data fetching.
For example, developers might have to make separate requests to retrieve a user profile, posts, and comments using a traditional REST API. When using GraphQL, they can retrieve all of this in one request.
GraphQL vs. REST
Here is how GraphQL compares to REST in some key areas:
Feature | GraphQL | REST |
---|---|---|
Data Fetching | The client specifies precisely what data is needed in a single request. | Predefined endpoints with fixed data responses, often resulting in over-fetching or under-fetching. |
API Structure | Uses a single endpoint for all requests (/graphql). | Multiple endpoints for different resources (e.g., /users, /posts). |
Data Manipulation | Uses queries (read), mutations (write), and subscriptions (real-time updates). | Relies on HTTP methods like GET, POST, PUT, and DELETE for data operations. |
Schema | Strongly typed schema defines available data and operations, making APIs self-documenting. | Lacks a unified schema; often requires additional documentation. |
Overhead and Bandwidth | Reduces overhead by allowing the client to request only the needed data. | Higher potential for data over-fetching, increasing bandwidth usage. |
How Optimizely Graph Works
Optimizely Graph is a multi-tenant SaaS service that allows you to search, query, and deliver content anywhere. It integrates with other Optimizely products, including CMS, SaaS CMS, and Commerce Connect. Using GraphQL, Optimizely Graph offers developers search and filtering capabilities, specifically the exact content needed, while making content consumption more efficient and faster.
Optimizely graph is typically used to search for or deliver content for headless but can also be leveraged in a traditional implementation.
Content Search: Developers can create custom search tools to turn user input into a GraphQL query and then process the results into a search results page. They can also extend the logic behind these queries to create customizable search experiences.
Content Delivery: A site’s content can be exposed as a graph that can be queried. This enables developers to build dynamic content blocks by querying data and shaping the results as needed. For example, you could build a ‘Suggested readings’ section that pulls the five most recent blog posts within a similar topic, displaying each post’s title, summary, and featured image in a neatly arranged content block.
Headless Content Delivery: Since GraphQL calls return data as a JSON object, Optimizely Graph enables cross-application and cross-framework content delivery. This means that it can perform headless content delivery. For instance, developers could create an app that pulls content from the CMS and displays it in a mobile-optimized format. This allows them to deliver customized mobile experiences using the same content found on the main website.
Key Features of Optimizely Graph
The key features offered by Optimizely Graph enable businesses to realize several benefits, including semantic search and using external data sources.
Semantic Search
Graph can use AI to understand the meaning behind keywords. For example, in a typical search, “Big Apple” might not bring up relevant results, but with a semantic search, it understands that you’re looking for New York City.
External Data Sources
Graph enables you to query data directly from your CMS and also allows for syncing and querying data from external sources. This makes it possible to connect data from multiple sources and access them all through a single endpoint.
Installation & Configuration of Optimizely Graph
Optimizely Graph is installed using an Optimizely.ContentGraph.CMS
NuGet package in the CMS solution. It is configured using the following settings in ASP.NET Core solution in appsettings.json
as follows:
"Optimizely": {
"ContentGraph": {
"GatewayAddress": "",
"AppKey": "",
"Secret": "",
"SingleKey": "",
"AllowSendingLog": "true"
}
}
Optimizely Graph leverages Content Delivery API under the hood; hence it must be configured on the site as follows in the ConfigureServices(IServiceCollection services) method of Startup.cs
:
services.ConfigureContentApiOptions(o =>
{
o.IncludeInternalContentRoots = true;
o.IncludeSiteHosts = true;
//o.EnablePreviewFeatures = true;// optional
});
services.AddContentDeliveryApi(); // required, for further configurations, see https://docs.developers.optimizely.com/content-cloud/v1.5.0-content-delivery-api/docs/configuration
services.AddContentGraph();
Additional Configurations for Synchronization
PropertyIndexing Modes
Identifying if a given property must be filtered or searched upon is important. Knowing this and disabling filtering aspects on certain properties improves the indexing and querying of items having these properties. The different modes are as follows:
OutputOnly Mode: The property is not used for filtering and searching purposes but will be returned as part of the query.
[GraphProperty(PropertyIndexingMode.OutputOnly)] public virtual string AStringProperty { get; set; }
Default Mode: The property is used for filtering but not for searching.
[GraphProperty(PropertyIndexingMode.Default)] public virtual string AStringProperty { get; set; }
Include Inheritance
To include results from inherited types of content type, you can set as follows:
services.AddContentGraph(configureOptions: options => { options.IncludeInheritanceInContentType = true; });
Extract Media
To extract the content media and index that content, use the following snippet:
services.AddContentGraph(configureOptions: options => { options.ExtractMedia = false; });
Configure Whitelist Items to Synchronize
To configure a whitelist of items to be synchronized, we can leverage the ContentIds
and ContentTypes
properties of the following object as shown below:
"Optimizely": {
"ContentGraph": {
"Include": {
"ContentIds": [],
"ContentTypes": []
},
"OnlySyncContentTypesInWhitelistToSchema": false
}
}
You can override this setting at runtime using the following code in Startup.cs
.
services.AddContentGraph(configureOptions: options =>
{
options.Include.ContentIds = new int[3] { 1, 2, 3 };
options.Include.ContentTypes = new string[2] { typeof(StandardPage).Name, typeof(ProductPage).Name };
});
Configuring Sync Version Content
The status of items that should be synchronized can be configured in appsettings.json
as follows: This synchronized draft and published content.:
"Optimizely": {
"ContentGraph": {
"ContentVersionSyncMode": "DraftAndPublishedOnly"
}
}
Configuring Referencing Items
We can force re-synchronization of referencing content items using this flag:
"Optimizely": {
"ContentGraph": {
"SyncReferencingContents": "false"
}
}
Configuring Content Types Synchronization on Start
This can be done with the following snippet:
services.Configure<EventIndexingOptions>(ops =>
{
ops.SyncContentTypesOnInit = true;
});
Configure Date to Datetime
The GraphQL schema Date type can be changed to Datetime from Date using the following snippet:
"Optimizely": {
"ContentGraph": {
"UseDateTimeGQLType": true
}
}
This change does not apply to the _modified field and is always Date
type.
Synchronization Types
The content synchronization for Optimizely Graph is done in one of two ways:
-
Event-driven synchronization — This is done based on an event, such as when a content type is created, updated, or deleted, or when content is published, or any other such event.
-
Schedule\On-Demand synchronization — This is based on schedule or on-demand synchronization from the admin area.
Event-driven is the preferred way to synchronize content between CMS and Optimizely Content Graph. However, there are places where you may need to use the scheduled or On-Demand synchronization to sync content. There are two types of synchronization jobs:
-
Optimizely Graph Content Synchronization Job — Synchronizes content types and data and is recommended to be run once a day
-
Optimizely Graph Delta Synchronization Job — This synchronization job syncs content that has changed since the last one and is recommended to run every 15 minutes.
Enabling/Disabling Languages
Whenever you enable a language, the content synchronization job has to be re-run to get the respective language content synchronized between the CMS and Optimizely Content Graph. Disabling a language deletes content from Optimizely Graph to save costs. As such, you cannot query disabled language content or get results in that disabled language.
Get More Out of Optimizely
Optimizely Graph helps developers improve their productivity with GraphQL. Optimizely also offers several other products, such as Optimizely One, that can help businesses get more out of their Optimizely implementation. If you’re one of those businesses, then Oshyn can help.
Oshyn is a certified Optimizely partner that provides a variety of services, from design planning to development to post-launch enhancements and maintenance. Contact us to learn how we can help you with your Optimizely solutions.
Related Insights
-
-
Oshyn
-
Oshyn
Optimizely One
Introducing a Marketing Operating System
-
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.