6

I am trying to request to get the Component Presentations on a Page by firing query in GraphQL


   {
     page(namespaceId: 1, publicationId: 7, pageId: 730)
     {
       itemId
       title
       url
       creationDate
       containerItems { 
         ... on ComponentPresentation {
           itemId
           component { 
             title
             multiMedia
           }
           componentTemplate {
             title
           }      
         }
       }
     }
   }

Lets say in SDL the component list names are NewsArticle, Article, SportArticle. I need to get in the same order in GraphQL. Instead of that, I am getting data in some order which is not the same as the Component Presentations list.

Any idea what is missing here or any area which I need to look at?

5
  • Dhara, can you try this link for more details docs.sdl.com/792149/653056/sdl-tridion-sites-9/…
    – Anand NS
    Feb 26 at 21:07
  • also refer to this post - see if this helps -> tridion.stackexchange.com/questions/20365/…
    – Anand NS
    Feb 26 at 21:09
  • @AnandNS I actually need the order of the component list which is in SDL. Sort functionality in GraphQL will work after I get all the list and it won't get the same order which is in SDL I believe. please correct me If I am wrong.
    – Dhara
    Feb 26 at 21:40
  • @Dhara - Is that page template used region? Is it a DXA page template?
    – Velmurugan
    Feb 26 at 22:26
  • @Velmurugan Yes it has used region.
    – Dhara
    Feb 26 at 22:29
7

To get the Component Presentations on a Page, There are two different types of component presentations, dynamic and embedded. Embedded templates are used when a component is added to a page and published only in the context of that page. Dynamic means that the component can be published out to the broker, in your case I would assume it's an embedded CP, then you will not be able to fetch your page content in your query but it will get the component id/title info only.

As far as I can see - It always returns like that not in the same order, not sure it's a bug or not raise it to SDL support. In case if you looking to get the page output then you can use this graphql query.

{
  page(namespaceId: 1, publicationId: 7, pageId: 730) 
  {
    itemId
    title
    url
    rawContent(renderContent:true)
    {
      data
    }
  }
}

Updated:

In Sites 9.5 you can use Data publishing to get the As-is, called “untyped content”, of course, you can also By defining custom semantic models that allow you to map JSON transformations to either change the structure of your content or retrieve only some fields of a JSON data fragment.

To fetch the As-is, called “untyped content” from GraphQL:

{
  page(namespaceId: 1, publicationId: 7, pageId: 730)  
  {
    itemId
    title
    url
    content {
      ... on UntypedContent
      {
        data
      }
    }
  }
}

I can see the response gives the right order with the region info.

Updated:

5
  • I might need to raise this issue in SDL support.
    – Dhara
    Mar 1 at 15:00
  • Do we get component region wise? that is, if a page has 2 region how can I filter to get only 1 region?
    – Dhara
    Mar 1 at 15:14
  • 2
    @Dhara I think you are looking for template-less data publishing. OOTB you can fetch your order. you are looking for including region info. updated my answer
    – Velmurugan
    Mar 1 at 17:01
  • I got region wise component in proper order. Thank you Do you have any docs that actually helps me to get more knowledge on graphQL.
    – Dhara
    Mar 1 at 18:09
  • 2
    @Dhara - Updated my answer
    – Velmurugan
    Mar 9 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.