Expand my Community achievements bar.

SOLVED

AEM 6.5 Headless | Fragment reference data type with multiple content fragment allowed

Avatar

Level 4

I have a content fragment model having a single-valued field of type Fragment reference, in which 2 Content Fragment models are allowed.

I am looking into the most effective approach to write a Graphql query handling both content fragment models within a single field. Our initial attempt encompassed the inclusion of fields from both content fragment models within the said field; however, this endeavour resulted in query disruptions. Upon execution of Graphql query it throws error:

 

Validation error of type FieldUndefined: Field 'title' in type 'AllFragmentModels' is undefined @ 'productList/items/flag/title'"

 

 

Your insights and recommendations on this matter would be greatly valued. Please share if you have any example queries for reference.
Update:

 

Find below a screenshot of the field showing the concerned field.

Mukesh_Kumar_Co_0-1691067352992.png

The query used is:

 

query productList($productID:String,$locale:String)

{productList(filter:{
  productID : {_expressions: [{value:$productID}]}},
  _locale : $locale
)
{items{
  flag{title,backgroundColor,flagColor,saveOffer},
}
}
}

 

 This query work fine if I only allow a single content fragment model in the field. Issue is only with multiple content fragment allowed. Wondering if I'm missing something..

1 Accepted Solution

Avatar

Correct answer by
Level 4

I think I figure out the issue. To share with everyone correct query is:

query productList($productID:String,$locale:String)

{productList(filter:{
  productID : {_expressions: [{value:$productID}]}},
  _locale : $locale
)
{items{
  flag {
      ... on ProductFlagModel{title,backgroundColor,flagColor,saveOffer},
  }
}
}

}

View solution in original post

3 Replies

Avatar

Employee Advisor

@Mukesh_Kumar_Co Please share the GraphQl query, resulting in error. Also, the screenshot of the Content Fragment Models, you are encompassing in a single query

Avatar

Correct answer by
Level 4

I think I figure out the issue. To share with everyone correct query is:

query productList($productID:String,$locale:String)

{productList(filter:{
  productID : {_expressions: [{value:$productID}]}},
  _locale : $locale
)
{items{
  flag {
      ... on ProductFlagModel{title,backgroundColor,flagColor,saveOffer},
  }
}
}

}