Is it possible to add variation filter in nested content fragment model within a content fragment in GraphQL? | Community
Skip to main content
Level 4
December 13, 2022

Is it possible to add variation filter in nested content fragment model within a content fragment in GraphQL?

  • December 13, 2022
  • 1 reply
  • 1532 views

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 } } } }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

krati_garg
Adobe Employee
Adobe Employee
December 13, 2022

@spidey1405 

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
      }
    }
  }
}
Level 4
December 13, 2022

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?

krati_garg
Adobe Employee
Adobe Employee
December 13, 2022

@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
}
}
}
}