Documentation Center

GraphQL requests working with typed custom metadata

If you, as an implementer, are aware of the typology and design of metadata in your Components and Pages, you can use this knowledge to create much more targeted metadata queries.

To start, take this simple typedComponent query, which fetches all metadata for a specific component by using the standard metadata subquery, CustomMetas:
typedComponent(namespaceId: 1, publicationId: 5, componentId: 374) {
  title
  creationDate
  updateDate
  ...on Article {
    articleBody {
      subheading
      content {
        html
      }
    }
  }
  customMetas {
    edges {
      node {
        key
        value
        valueType
      }
    }
  }
}

The above query, in addition to fetching some general and custom content fields, also fetches all metadata as a flat list of untyped key-value pairs.

But thanks to Semantic Content Modeling, you can fetch metadata in a more directed way, if you as an implementer know how metadata is organized in the Metadata Schema on Content Manager. Take, for example, the following items query:
items(filter:{itemTypes:[ARTICLE]}) {
  edges {
    node {
      ...on Article {
        metadata {
          latitude
          longitude
        }
      }
    }
  }
}

Not only can you directly access the metadata fields whose name you know, you can also follow any Component link fields or Keyword link fields within the metadata in order to drill down further.

These two types of metadata queries, customMetas and metadata, can be combined in the same query to suit your specific needs.

Another property, customMetasStructure, returns a map of metadata, rather than the flat list offered by the customMetas property. For example:
customMetasStructure {
  data
}