Skip to content

Commit

Permalink
CTC-2299 Extend filtering examples on linked items
Browse files Browse the repository at this point in the history
  • Loading branch information
jancerman committed Jun 7, 2024
1 parent 5341439 commit 936c40e
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 25 deletions.
26 changes: 22 additions & 4 deletions graphql/filter-content/filtering_get_items_by_linked_item.graphql
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
# Gets items attributed to Jane.
query GetArticlesByAuthor {
article_All(where: {author: {containsAll: ["jane_doe"]}}) {
// # Gets a list of items where the 'my_page' item is used in the 'navigation' element.
query GetItemsByUsedIn {
page_All(where: {navigation: {containsAll: ["my_page"]}}) {
items {
title
}
}
}

# Gets items attributed to at least Jane, John, or both.
# Gets items linked to at least Jane, John, or both.
query GetArticlesByOneOfAuthors {
article_All(where: {author: {containsAny: ["jane_doe", "john_wick"]}}) {
items {
title
}
}
}

# Gets pages linking travel insurance as their subpage.
query GetArticlesTaggedWithATerm {
article_All(where: {subpages: {containsAll: ["travel_insurance"]}}) {
items {
title
}
}
}

# Gets pages linking at least travel insurance, car insurance, or both as their subpage.
query GetArticlesTaggedWithTerms {
article_All(where: {subpages: {containsAny: ["travel_insurance", "car_insurance"]}}) {
items {
title
}
}
}
20 changes: 17 additions & 3 deletions java/filter-content/filtering_get_items_by_linked_item.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
// Gets items attributed to Jane.
// Gets a list of items where the 'my_page' item is used in the 'navigation' element.
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterContains("elements.author", "jane_doe")
.filterContains("elements.navigation", "my_page")
.build()
);


// Gets items attributed to at least Jane, John, or both.
// Gets items linked to at least Jane, John, or both.
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterAny("elements.author", "jane_doe", "john_wick")
.build()
);

// Gets pages linking travel insurance as their subpage.
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterContains("elements.subpages", "travel_insurance")
.build()
);

// Gets pages linking at least travel insurance, car insurance, or both as their subpage.
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterAny("elements.subpages", "travel_insurance", "car_insurance")
.build()
);
16 changes: 13 additions & 3 deletions js/filter-content/filtering_get_items_by_linked_item.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// Gets items attributed to Jane.
// Gets a list of items where the 'my_page' item is used in the 'navigation' element.
const response = await deliveryClient.items()
.containsFilter('elements.author', ['jane_doe'])
.containsFilter('elements.navigation', ['my_page'])
.toPromise();

// Gets items attributed to at least Jane, John, or both.
// Gets items linked to at least Jane, John, or both.
const response = await deliveryClient.items()
.anyFilter('elements.author', ['jane_doe', 'john_wick'])
.toPromise();

// Gets pages linking travel insurance as their subpage.
const response = await deliveryClient.items()
.containsFilter('elements.subpages', ['travel_insurance'])
.toPromise();

// Gets pages linking at least travel insurance, car insurance, or both as their subpage.
const response = await deliveryClient.items()
.anyFilter('elements.subpages', ['travel_insurance', 'car_insurance'])
.toPromise();
16 changes: 13 additions & 3 deletions net/filter-content/filtering_get_items_by_linked_item.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// Gets items attributed to Jane.
// Gets a list of items where the 'my_page' item is used in the 'navigation' element.
IDeliveryItemListingResponse<object> response = await deliveryClient.GetItemsAsync<object>(
new ContainsFilter("elements.author", "jane_doe")
new ContainsFilter("elements.navigation", "my_page")
);

// Gets items attributed to at least Jane, John, or both.
// Gets items linked to at least Jane, John, or both.
IDeliveryItemListingResponse<object> response = await deliveryClient.GetItemsAsync<object>(
new AnyFilter("elements.author", "jane_doe", "john_wick")
);

// Gets pages linking travel insurance as their subpage.
IDeliveryItemListingResponse<object> response = await deliveryClient.GetItemsAsync<object>(
new ContainsFilter("elements.subpages", "travel_insurance")
);

// Gets pages linking at least travel insurance, car insurance, or both as their subpage.
IDeliveryItemListingResponse<object> response = await deliveryClient.GetItemsAsync<object>(
new AnyFilter("elements.subpages", "travel_insurance", "car_insurance")
);
16 changes: 13 additions & 3 deletions php/filter-content/filtering_get_items_by_linked_item.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?php
// Gets items attributed to Jane.
// Gets a list of items where the 'my_page' item is used in the 'navigation' element.
$items = $client->getItems((new QueryParams())
->contains('elements.author', 'jane_doe'));
->contains('elements.navigation', 'my_page'));

// Gets items attributed to at least Jane, John, or both.
// Gets items linked to at least Jane, John, or both.
$items = $client->getItems((new QueryParams())
->any('elements.author', ['jane_doe','john_wick']));
?>

<?php
// Gets pages linking travel insurance as their subpage.
$items = $client->getItems((new QueryParams())
->contains('elements.subpages', 'travel_insurance'));

// Gets pages linking at least travel insurance, car insurance, or both as their subpage.
$items = $client->getItems((new QueryParams())
->any('elements.subpages', ['travel_insurance','car_insurance']));
?>
16 changes: 13 additions & 3 deletions rest/filter-content/filtering_get_items_by_linked_item.curl
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Gets items attributed to Jane.
# Gets a list of items where the 'my_page' item is used in the 'navigation' element.
curl --request GET \
--url 'https://deliver.kontent.ai/<YOUR_ENVIRONMENT_ID>/items?elements.author[contains]=jane_doe' \
--url 'https://deliver.kontent.ai/<YOUR_ENVIRONMENT_ID>/items?elements.navigation[contains]=my_page' \
--header 'content-type: application/json'

# Gets items attributed to at least Jane, John, or both.
# Gets items linked to at least Jane, John, or both.
curl --request GET \
--url 'https://deliver.kontent.ai/<YOUR_ENVIRONMENT_ID>/items?elements.author[any]=jane_doe,john_wick' \
--header 'content-type: application/json'

# Gets pages linking travel insurance as their subpage.
curl --request GET \
--url 'https://deliver.kontent.ai/<YOUR_ENVIRONMENT_ID>/items?elements.subpages[contains]=travel_insurance' \
--header 'content-type: application/json'

# Gets pages linking at least travel insurance, car insurance, or both as their subpage.
curl --request GET \
--url 'https://deliver.kontent.ai/<YOUR_ENVIRONMENT_ID>/items?elements.subpages[any]=travel_insurance,car_insurance' \
--header 'content-type: application/json'
12 changes: 9 additions & 3 deletions ruby/filter-content/filtering_get_items_by_linked_item.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Gets items attributed to Jane.
delivery_client.items('elements.author'.contains('jane_doe'))
# Gets a list of items where the 'my_page' item is used in the 'navigation' element.
delivery_client.items('elements.navigation'.contains('my_page'))

# Gets items attributed to at least Jane, John, or both.
# Gets items linked to at least Jane, John, or both.
delivery_client.items('elements.author'.any('jane_doe', 'john_wick'))

# Gets pages linking travel insurance as their subpage.
delivery_client.items('elements.subpages'.contains('travel_insurance'))

# Gets pages linking at least travel insurance, car insurance, or both as their subpage.
delivery_client.items('elements.subpages'.any('travel_insurance', 'car_insurance'))
16 changes: 13 additions & 3 deletions ts/filter-content/filtering_get_items_by_linked_item.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// Gets items attributed to Jane.
// # Gets a list of items where the 'my_page' item is used in the 'navigation' element.
const response = await deliveryClient.items()
.containsFilter('elements.author', ['jane_doe'])
.containsFilter('elements.navigation', ['my_page'])
.toPromise();

// Gets items attributed to at least Jane, John, or both.
// Gets items linked to at least Jane, John, or both.
const response = await deliveryClient.items()
.anyFilter('elements.author', ['jane_doe', 'john_wick'])
.toPromise();

// Gets pages linking travel insurance as their subpage.
const response = await deliveryClient.items()
.containsFilter('elements.subpages', ['travel_insurance'])
.toPromise();

// Gets pages linking at least travel insurance, car insurance, or both as their subpage.
const response = await deliveryClient.items()
.anyFilter('elements.subpages', ['travel_insurance', 'car_insurance'])
.toPromise();

0 comments on commit 936c40e

Please sign in to comment.