GraphQL Query reference issue | Community
Skip to main content
Level 2
November 22, 2024
Solved

GraphQL Query reference issue

  • November 22, 2024
  • 2 replies
  • 609 views

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

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 Madhur-Madan

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

2 replies

Madhur-Madan
Community Advisor
Madhur-MadanCommunity AdvisorAccepted solution
Community Advisor
November 22, 2024

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

gkalyan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
November 23, 2024

@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-api/sample-queries#sample-wknd-nested-fragment-multiple-model