Create contracts
Implement Optimizely CMS contracts to standardize content types, streamline management, and simplify data access with Optimizely Graph.
Administrators create and manage contracts in the Settings UI; developers implement them in code.
How contracts work
Contracts, also known as interfaces, define shared properties and behaviors across content types and establish a standardized structure for consistency. Integrate a contract with Optimizely Graph to extend these benefits to its content delivery APIs and support more flexible content querying.
For example, you can create a contract called Categorizable and specify that any content type implementing it must include the properties Category and Tags.
Content types such as Blog article, Press release, and News article can then implement this Categorizable contract. By doing so, you ensure the following:
- Every Blog article consistently has a Category and Tags.
- Every Press release consistently has a Category and Tags.
- Every News article consistently has a Category and Tags.
This consistency provides the following advantages:
- Consistent content management – Content editors encounter a uniform experience. Regardless of the specific content type, the Category and Tags fields always display, promoting standardized metadata application.
- Enhanced search and filtering – Developers and content managers search for, group, and filter content based on the contract's properties. For example, retrieve all Categorizable content and filter by Category: Marketing or Tag: Product Launch, without differentiating between Blog article, Press release, or News article.
- Code reusability – Developers write generic code that interacts with any content type implementing a specific contract. This reduces redundancy, simplifies development, and improves maintainability.
Contracts and Optimizely Graph
Contracts extend to Optimizely Graph, changing how developers query and consume content. When you define a contract in CMS 13, CMS automatically generates a corresponding GraphQL schema (a typed representation of the contract's properties) in Optimizely Graph.
- Unified querying – Developers write a single GraphQL query targeting the Categorizable contract schema in Optimizely Graph. The query retrieves content from all implementing content types, such as Blog article, Press release, and News article.
- Simplified data access – Developers retrieve all relevant content adhering to the Categorizable structure in a single query, without writing separate queries for each content type. This approach simplifies data retrieval for applications that consume content from Optimizely Graph.
- Decoupled development – Contracts decouple front-end development from specific content type implementations. Developers build components that expect any Categorizable content, and Optimizely Graph delivers it consistently regardless of the original CMS content type.
Create a contract
Create a contract to define a reusable set of properties that multiple content types share. Contracts enforce consistent metadata and unlock unified queries in Optimizely Graph.
-
Go to Settings > Content Types and select Create New > Contract. The Create New Contract window displays.
- Name – Enter the internal programmatic name for the contract (such as Categorizable).
- Display name – Enter the name that content editors see (such as Categorizable content type).
- Description – Provide a description of what content types implementing this contract must include (for example, Any content type with this contract must have Category and Tags properties.).
-
Click Properties to add properties to the contract.
Add the properties that all content types implementing this contract must include. For example, if your contract is Categorizable, add properties such as Category and Tags. For each property, configure its settings.
- Display in edit view – Select this option to make the property visible and editable in the content editor's view when a content type implements this contract.
- Display name – The label for the property that content editors see.
- Help text – Provide guidance for content editors on how to use this property.
- Sort index – Determines the order in which properties appear in the UI.
- Property Group – Assign the property to a group to organize properties in the UI.
Implement the contract in content types
NoteCreate the properties on the content types before applying the contract.
After defining the contract (Categorizable content type) and its properties (Category and Tags), apply it to other content types.
For example, go to the Contracts section of the Blog article, Press release, or News page content type and select Implement or Inherit for the Categorizable content type contract.
Graph query example based on contracts
The following GraphQL query retrieves items categorized as "Meetup", including their metadata, tags, and excerpt and main body for blog articles:
query MyQuery {
Categorizable(where: { Category: { eq: "Meetup" } }) {
items {
_metadata {
key
displayName
}
Category
Tags
... on BlogArticle {
Excerpt
MainBody
}
}
}
}