AEM 6.5 Headless | Fragment reference data type with multiple content fragment allowed | Community
Skip to main content
Mukesh_Kumar_Co
Level 3
August 3, 2023
Solved

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

  • August 3, 2023
  • 1 reply
  • 977 views

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.

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..

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mukesh_Kumar_Co

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

1 reply

krati_garg
Adobe Employee
Adobe Employee
August 3, 2023

@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

Mukesh_Kumar_Co
Level 3
August 3, 2023

Hi @krati_garg , I have updated the question to add the required details.

Mukesh_Kumar_Co
Mukesh_Kumar_CoAuthorAccepted solution
Level 3
August 3, 2023

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