2

I created a GraphQL request to get all component details based on the regions of a page.

{
  page(namespaceId: 1, publicationId: 2, pageId: 231) {
    itemId
    title
    url
    regions {
        components {
            itemId
            multiMedia
            ... on Component {
                content { 
                    ... on UntypedContent {
                        data
                    }
                }
            }
        }
    }
  }
}

But The response doesn't contain any metadata field information.

Is there any way to include metadata in the above query?

1
  • Good question and welcome to Tridion Stack Exchange, we're glad you joined! Commented Apr 5, 2023 at 20:26

1 Answer 1

3

In the UntypedContent - will not fetch the metadata info. It just holds the page output data, the fact that in the backend metadata is stored separately, and you need to use metadata { metadataField }

In Sites 9.6, instead of using UntypedContent you can publish using data-template-less headless publishing to use Semantic Content Model GraphiQL query.

Here is a sample graphiql query with metadata with the corresponding output.

{
  page(namespaceId: 1, publicationId: 2, pageId: 231) {
    publicationId
    itemId
    title
    regions {
      name
      components {
        itemId
        title
        ... on FinanceArticle {
          heading
          subHeading
          bodyText {
            html
          }
          numberField
          dateField
          image {
            ... on Image {
              title
              metadata {
                altText
              }
              variants {
                edges {
                  node {
                    url
                    downloadUrl
                  }
                }
              }
            }
          }
          metadata {
            metadataField1
            financeArticleType {
              ... on Keyword {
                title
                description
                key
              }
            }
          }
        }
      }
    }
  }
}

Here is the output:

{
  "data": {
    "page": {
      "publicationId": 14,
      "itemId": 719,
      "title": "Finance Articles Page",
      "regions": [
        {
          "name": "Main",
          "components": [
            {
              "itemId": 718,
              "title": "Finance Article Sample 1",
              "heading": "Heading - Finance Article Sample 1",
              "subHeading": "Subheading - Finance Article Sample 1",
              "bodyText": {
                "html": "<p>Body Text content in Finance Article Sample 1.</p>"
              },
              "numberField": 11,
              "dateField": "2023-01-31T02:54:47.000",
              "image": {
                "title": "Finance Article Image 1",
                "metadata": {
                  "altText": "Alt Text - Finance Article Image 1"
                },
                "variants": {
                  "edges": [
                    {
                      "node": {
                        "url": "/media/skyline.jpg",
                        "downloadUrl": "http://localhost:8081/cd/api/binary/1/14/717"
                      }
                    }
                  ]
                }
              },
              "metadata": {
                "metadataField1": "Metadata value!",
                "financeArticleType": {
                  "title": "Internal Report",
                  "description": "Internal Report",
                  "key": "InternalReport"
                }
              }
            },
            {
              "itemId": 720,
              "title": "Finance Article Sample 2",
              "heading": "Heading - Finance Article Sample 2",
              "subHeading": "Subheading - Finance Article Sample 2",
              "bodyText": {
                "html": "<p>Body Text content</p>\n<p>More content</p>"
              },
              "numberField": 1200,
              "dateField": "2022-12-29T02:54:47.000",
              "image": {
                "title": "Finance Article Image 2",
                "metadata": {
                  "altText": "Alt Text - Finance Article Image 2"
                },
                "variants": {
                  "edges": [
                    {
                      "node": {
                        "url": "/media/blueprint.jpg",
                        "downloadUrl": "http://localhost:8081/cd/api/binary/1/14/721"
                      }
                    }
                  ]
                }
              },
              "metadata": {
                "metadataField1": "Metadata content",
                "financeArticleType": {
                  "title": "End of Year Announcement",
                  "description": "End of Year Announcement",
                  "key": "EndOfYearResults"
                }
              }
            }
          ]
        }
      ]
    }
  }
}

I hope it helps.

4
  • Just in case, note that the Content Manager needs to have the Region Schema's Metadata field set to be publishable. If there is a Schema change needed, do we also need to restart the content service? Commented Apr 5, 2023 at 20:32
  • Thanks Velmurugan. We are trying to make a Get page GraphQL query request as generic one, due to page count(more than 100). Sematic content model solution won't work for us.
    – Sasi
    Commented Apr 5, 2023 at 21:11
  • @AlvinReyes, The schema changes need only publishing components, Not required for content service restart, there is a config in the content service application.properties to enable scm and graphql.scm.update.interval that needs to be managed based on customer needs.
    – Velmurugan
    Commented Apr 6, 2023 at 8:07
  • Ah, good info. I was wondering how to get CM changes recognized in CD for Semantic Content Models! Commented Apr 6, 2023 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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