'How to implement groupBy in graphQl with contentful
We want to fetch contentful collection items based on a key grouping. I am using the apollo graphQl to query the contentful api for retrieving the data, Where we have plain collection of data and I want to group the collection based on a key available in the content model.
levelCollection(limit: 11) {
items{
groupBy {
name {
key
connection {
edges {
node {
id
url
}
}
}
}
}
Where LevelCollection is a collection of with following attributes
{
id
url
key
}
I want the output of the query to be grouped based on the key attribute in that collection
Expected Output:
{
levelCollection:{
key: 'group 1',
items: [
{
id: 'id1',
url: 'url1'
},
{
id: 'id1',
url: 'url1'
}
]
}
}
It is expected to group the data based on the key and get the the collection of grouped items against the key.
is there any way to achieve the dynamic grouping in graphQl on the collections from contentful
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
