Cyclic queries
Optimizely GraphQL queries with self or cross references.
Important
This feature is experimental and highly incompatible with many 3rd party libs
Description
Optimizely Graph is a product at the top of Optimizely CMS and mostly reflects the data structure of the CMS. Referenced contents are so common in the CMS structure and it is highly expected that Optimizely Graph should follow the CMS model. Although declaration-wise, it is straightforward, it violates the GraphQL specification, so it is disabled by default.
So far, to solve the self-referenced data problem, Recursive directive is introduced, allowing the declaration of self-referenced. For example, ContentA -> ContentB -> ContentC -> ContentA
contents. However, it has not solved the problem fully because the actual data structure also contains cross-referenced. For example, ContentA -> ContentB AND ContenB -> ContentA
data.
As a complete solution, Optimizely Graph lets you query with self or cross references from now on. For information, see the following examples.
Important
Although your queries work on the GraphiQL page, they might be broken on your client app due to the limitation of your third party libraries.
Self-referenced query example
query self {
Content {
items {
...IContent
}
}
}
fragment IContent on IContent {
... on StartPage {
MainContentArea {
ContentLink {
Expanded {
...IContent
}
}
}
}
}
Cross-referenced query example
query cross {
Content {
items {
...IContent
}
}
}
fragment IContent on IContent {
Name
... on StandardPage {
...StandardPage
}
}
fragment StandardPage on StandardPage {
Status
MainContentArea {
ContentLink {
Expanded {
...IContent
}
}
}
}
Limitations
_link
and_children
fields are not supported with cyclic fragments.- Only
items
root field is supported. - If you use
@graphql-codegen/cli
,typescript-operations
plugin is not supported.
Updated 27 days ago