I have a content fragment which includes a nested content fragment and I want to apply variation only to the nested CF results. Is it possible to do so via GQL?
Example:
query($variation:String!){
articleByPath(_path: "/content/dam/wknd-shared/en/magazine/alaska-adventure/alaskan-adventures") {
item {
authorFragment(variation: $variation) {
_path
_variation
firstName
lastName
birthDay
}
main {
html
markdown
plaintext
json
}
}
}
}
Views
Replies
Total Likes
I believe there is no single query, which could get a variation of a nested fragments, but I could come up with below set of queries to achieve this:
With below query, you can get the variation name of a nested fragment:
{
articleByPath (_path: "/content/dam/wknd/en/magazine/skitouring/skitouring") {
item {
_path
author
referencearticle {
_path
author
_variations
}
}
}
}
Here referencearticle is a nested fragment, and variation1 is one of its variation
You can then fetch content out of variation1 of the nested fragment:
{
articleByPath(_path: "/content/dam/wknd-shared/en/magazine/alaska-adventure/alaskan-adventures", variation: "variation1") {
item {
authorFragment {
_path
_variation
firstName
lastName
birthDay
}
main {
html
markdown
plaintext
json
}
}
}
}
Hi Krati, the query
{ articleByPath(_path: "/content/dam/wknd-shared/en/magazine/alaska-adventure/alaskan-adventures", variation: "variation1") { item { authorFragment { _path _variation firstName lastName birthDay } main { html markdown plaintext json } } } }
would return me article with the variation "variation1" however I am interested in something like this:
query($variation:String!){ articleByPath(_path: "/content/dam/wknd-shared/en/magazine/alaska-adventure/alaskan-adventures") { item { authorFragment(variation: $variation) { _path _variation firstName lastName birthDay } main { html markdown plaintext json } } } }
Is this possible?
@spidey1405 Not exactly the above query, but below one worked for me:
query($variation:String!){
articleList( variation: $variation) {
items {
_path
referencearticle {
_path
_variations
}
main {
html
markdown
plaintext
json
}
}
}
}
This one I am aware of but its not solving the use case. I wanted to add variation to the nested model
I twisted the query a bit and found that variable argument you are passing to the main fragment, is indeed passing to nested fragment. Please check below, main Content Fragment does not have any variations, while nested fragment has 2 variations, when I pass "test" as parameter, it picks "test" variation of nested fragment.
You just need to place below code fragment to the item, where you want to apply the variable parameter:
main { html markdown plaintext json }
Query:
query($variation:String!){
articleList(variation: $variation){
items {
_path
_variations
referencearticle{
_path
_variations
main {
html
markdown
plaintext
json
}
}
}
}
}
Thank you very much for the reply @krati_garg
However this is not exactly desired. What I mean to say is that it should apply the variation only in the nested part and not in the whole articleList as you showed.
It should apply variation in the referencearticle but should return the master result of articleList
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies