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.
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.
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.
customMetasStructure, returns a map of metadata, rather than the flat list offered by the customMetas property. For example:
customMetasStructure {
data
}