GraphQL request for getting all Components of a certain content type
If your authors give each Component a value for a custom metadata key you created called contentType, you can use a GraphQL request to filter by content type. This lets you create, say, a dynamic webpage showing all content of that type.
The following sample shows a request for some basic properties of Components whose content type was set to "News Article" as well as a possible response to the request.
{
items (
filter: {
itemTypes: [COMPONENT],
customMeta: { key: "contentType", value: "News Article" }
}
) {
edges {
node {
... on Component {
itemId
title
creationDate
schemaId
}
}
}
}
}
{
"data": {
"items": {
"edges": [
{
"node": {
"itemId": 269,
"title": "News Articles Index",
"creationDate": "2016-12-08T03:08:53+01:00",
"schemaId": 135
}
},
{
"node": {
"itemId": 273,
"title": "Latest News",
"creationDate": "2016-12-08T03:08:55+01:00",
"schemaId": 135
}
},
{
"node": {
"itemId": 1010,
"title": "News Articles Index",
"creationDate": "2018-01-22T06:48:51+01:00",
"schemaId": 787
}
},
{
"node": {
"itemId": 1016,
"title": "Latest News",
"creationDate": "2018-01-22T06:48:52+01:00",
"schemaId": 787
}
}
]
}
}
}