GraphQL requests involving custom metadata filtering
This series of samples demonstrates the use of scope while filtering on custom metadata.
{
items(
filter: {
customMeta: {scope: Item, key: "mykey", value: "42"}
}
) {
edges {
node {
id
publicationId
namespaceId
itemId
itemType
title
customMetas {
edges {
node {
key
value
}
}
}
}
}
}
}
Now we explore how changing the filter affects the results of the query.
filter: part of the query, changing scope: Item into scope:Publication:
filter: {
customMeta: {scope: Publication, key: "mykey", value: "42"}
}
itemTypes to your filter:
filter: {
itemTypes: [PUBLICATION],
customMeta: {scope: Publication, key: "mykey", value: "42"}
}
itemTypes to [Publication], the scope property in customMeta becomes irrelevant. A query with the filter above gives the same result as a query with the following filter:
filter: {
itemTypes: [PUBLICATION],
customMeta: {scope: Item, key: "mykey", value: "42"}
}
- Three Publications called
Pub1,Pub2andPub3. Pub1contains two items:Item1, which has item type 16, andItem2, which has item type 64 (which means it's a Page).Item1has themykeycustom metadata Keyword set to the value 42. (Item2has no custom metadata of any kind.)Pub2also contains two items:Item3andItem4, both of which have item type 16.Item3has themykeycustom metadata Keyword set to the value 42. (Item4has no custom metadata of any kind.)- Finally,
Pub3only contains one item:Item5, which is of item type 64 (which means it's a Page) and also has no custom metadata set.
The set of sample filters shows the use of ItemInPublication scope. You use this scope to retrieve items located in a Publication that contains items tagged with a specified custom metadata key-value pair.
ItemInPublication:
filter: {
customMeta: {scope: ItemInPublication, key: "mykey", value: "42"}
}
Applied to the sample data set, the query returns all items associated with Publications that contain items tagged with mykey=42 (including the Publications themselves). That is, the query returns Pub1, Pub2, Item1, Item2, Item3 and Item4.
itemTypes property to our filter:
filter: {
itemTypes: [PUBLICATION],
customMeta: {scope: ItemInPublication, key: "mykey", value: "42"}
}
Applied to the sample data set, the query returns all Publications that contain items tagged with mykey=42. That is, the query returns Pub1 and Pub2.
itemTypes property in our filter:
filter: {
itemTypes: [PAGE],
customMeta: {scope: ItemInPublication, key: "mykey", value: "42"}
}
Applied to the sample data set, the query returns all Pages located in Publications that contain items tagged with mykey=42. That is, the query returns Item2 only. The reason why Item1, Item3 and Item4 are not returned is because they are not Pages; the reason why Item5 is not returned is because it isn't located in a Publication containing an item tagged with mykey=42.