Expand my Community achievements bar.

SOLVED

GraphQL Query reference issue

Avatar

Level 2

I am having an issue with Content Fragment GraphQL Query.

 

I have model A which holds a fragment reference to Model B.

 

Model A has name field and ModelB reference. Model B has a field called category.

 

I want to get both the result in 1 query like

 

modelAList{
items{
  name
  modelBList
  {
    category
  }
 }
}

 

But it gives me syntax error "message": "Validation error (FieldUndefined@ Field 'category' in type 'AllFragmentModels' is undefined",

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ShamliKh ,

The syntax used to reference the fragment in your query is incorrect.
Try the below mentioned syntax

modelAList{
items{
  name
  modelBList
  {
     ... on ModelBModel{
          category
     }
  }
 }
}


Thanks,
Madhur Madan

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @ShamliKh ,

The syntax used to reference the fragment in your query is incorrect.
Try the below mentioned syntax

modelAList{
items{
  name
  modelBList
  {
     ... on ModelBModel{
          category
     }
  }
 }
}


Thanks,
Madhur Madan

Avatar

Community Advisor

@ShamliKh 

As Madhur mentioned, the reference syntax you are using needs correction. 

 

You can refer to the sample query from Adobe here

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql...