GraphQL API query | Community
Skip to main content
Level 4
April 1, 2021
Solved

GraphQL API query

  • April 1, 2021
  • 1 reply
  • 1121 views

I've been following the GraphQL API in AEM tutorial here: https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/graphql/fragment-references.html?lang=en#graphql

 

On the page above it demonstrates how to add a fragment reference for a contributor to an adventure. It then shows how to construct a query to find the contributor(s) for a particular adventure:

 

{ adventureByPath(_path:"/content/dam/wknd/en/adventures/bali-surf-camp/bali-surf-camp") { item { _path adventureTitle adventureContributor { fullName ... } } } } }

 

Is it possible to write a reversal of this query where you can find all of the adventures that a contributor has contributed to?

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 Pawan-Gupta

Hello,

 

Just want to add my thoughts. 

 

I would look at it from Model and Model associations. Now in this case the model is adventure which has association of contributor and model instances (fragments) are created for adventure.

 

So, looking at this scenario the query should be finding out all adventure associated to specific contributor or set of contributor under adventure path (because otherwise query or filtering will be cumbersome), until unless you have other way model creation where contributor has association of adventures and created as model instances (fragments) in filter.

 

(i hope, was able to clear it)

 

refer very good video around same: https://adapt.to/2020/en/schedule/graphql-services-in-the-aem-world.html

1 reply

Pawan-Gupta
Pawan-GuptaAccepted solution
Level 8
April 1, 2021

Hello,

 

Just want to add my thoughts. 

 

I would look at it from Model and Model associations. Now in this case the model is adventure which has association of contributor and model instances (fragments) are created for adventure.

 

So, looking at this scenario the query should be finding out all adventure associated to specific contributor or set of contributor under adventure path (because otherwise query or filtering will be cumbersome), until unless you have other way model creation where contributor has association of adventures and created as model instances (fragments) in filter.

 

(i hope, was able to clear it)

 

refer very good video around same: https://adapt.to/2020/en/schedule/graphql-services-in-the-aem-world.html

Level 4
April 6, 2021

Thanks for your thoughts and the link to the video, very helpful! I've had another think and was able to get this to work by applying a filter to the nested adventureContributor property.

 

Something like:

 

{ adventureList(filter: { adventureContributor: { fullName: { _expressions: [ { value: "Jacob Wester" _operator: EQUALS } ] } } }) { items { _path adventureContributor { _path fullName } } } }