Expand my Community achievements bar.

SOLVED

GraphQL API query

Avatar

Level 4

I've been following the GraphQL API in AEM tutorial here: https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/g...

 

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?

1 Accepted Solution

Avatar

Correct answer by
Level 9

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 9

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

Avatar

Level 4

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