AEM content fragment graphQL, query all parent fragments that includes given content path

746 Views Asked by At

Bascially, what I need is , given a content path, e.g let's say a piece of content fragment built by Product Model. enter image description here

Then I have another content fragement (let's say it is parent content fragement) built by a diff model called 'PageBody' , this parent content fragement includes that product content fragment. enter image description here

Now I wish to build a graphql query, to retrieve all/any parents content fragement JSON that includes this product enter image description here

graphql query:

query itemRefByPath($path:String!){
  productByPath (_path: $path) {
    item{
      _path
    }
    
    _references {
      ... on ProductModel {
        __typename
        _path        
      }
      ... on PageRef {
        _path
      }
      ... on PageModel {
        _path
      }
      
      ... on PageBodyModel {
        _path
      }
      
      ... on TabModel {
        _path
      }
    }
  }
}

But as you can see, the references I got empty... Anyone could advise me what I have done wrong? Guess my graphql syntax got issue right? Please provide me some sample query code to help Thanks

1

There are 1 best solutions below

0
Shivam Sahil On

You're trying to query by _path. The _path of child and parent can't be same. I would suggest putting in the schema of both and then asking your question