Documentation Center

GraphQL requests using the componentPresentations() field

Use the componentPresentations() field to query Component Presentations specifically. This type of query is similar to the items() query.

This sample query fetches Component Presentations from the Publication with ID 16 in Tridion Sites. The Component Presentations must additionally meet the following requirements:
  • They must have a metadata key name set to the value Sitemap.
  • They must be the result of rendering Components based on a Schema with ID 815.
  • They must have been rendered using a Component Template with ID 825.
  • They must have been most recently published between 25 May 2018 at 10:07 AM, Central European Time, and 28 July 2018 at 7:48 AM, Central European Time.
The following fields should be returned for each Component Presentation:
  • The cursor (used for fetching the next batch of results)
  • The item type (should always be 2048, that is, Component Presentation)
  • The ID of the Component rendered as this Component Presentation
  • The title of the Component
  • The date and time at which the Component was most recently published (should fall within the range specified)
  • The date and time at which the Component was created
  • The date and time at which the Component was most recently updated
  • The date and time at which the Component was published for the first time
  • The ID of the Component Template used to render the Component (should always be 825)
  • The title of the Component Template used to render the Component
  • The raw data of the Component Presentation

The results should be presented sorted ascending by their most recent publish date, and only the first 10 results must be shown.

Here is the query that matches these specifications:
{
  componentPresentations(
    namespaceId: 1,
    publicationId: 16,
    filter: {
      customMeta: {key: "name", value: "Sitemap"},
      schema: {id: 815},
      template: {id: 825},
      dateRange: {
        type: LAST_PUBLISH_DATE,
        start: "2018-05-22T10:07:00+02:00",
        end: "2018-07-28T07:48:00+02:00",
      },
    }
    sort: {sortBy: LAST_PUBLISH_DATE, order: Ascending},
    first: 10
  ) {
    edges {
      cursor
      node {
        itemType
        component {
          itemId
          title
          lastPublishDate
          creationDate
          updatedDate
          initialPublishDate
        }
        componentTemplate {
          itemId
          title
        }
        rawContent {
          data
        }
      }
    }
  }
}
Here is an example of what the result of this query might look like (containing one Component Presentation):
{
  "data": {
    "componentPresentations": {
      "edges": [
        {
          "cursor": "MQ==",
          "node": {
            "itemType": 2048,
            "component": {
              "itemId": 1033,
              "title": "Sitemap",
              "lastPublishDate": "2018-05-28T08:48:00+02:00",
              "creationDate": "2018-01-22T05:48:56+01:00",
              "updatedDate": "2018-01-22T05:48:56+01:00",
              "initalPublishDate": "2018-04-20T13:31:21+02:00",
            },
            "componentTemplate": {
              "itemId": 825,
              "title": "Generate Data Presentation"
            },
            "rawContent": {
              "data": {
                "Id": "1033",
                "ComponentTemplate": {
                  "Id": "825",
                  "RevisionDate": "0001-01-01T00:00:00"
                },
                "Folder": {
                  "Id": "211",
                  "Title": "Content"
                },
                "Content": {
                  "headline": "Sitemap",
                  "image": {
                    "$type": "EntityModelData",
                    "Id": "987"
                  },
                  "articleBody": {
                    "$type": "ContentModelData",
                    "content": {
                      "$type": "RichTextData",
                      "Fragments": [
                        "\n\t\t<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>\n\t\t"
                      ]
                    }
                  }
                },
                "Metadata": {
                  "standardMeta": {
                    "$type": "ContentModelData",
                    "description": "Sed do eiusmod tempor incididunt ut labore et dolor magna aliqua.",
                    "name": "Sitemap",
                    "introText": "Can't find what you want? Check the sitemap..."
                  }
                },
                "SchemaId": "815"
              }
            }
          }
        }
      ]
    }
  }
}