Limit the number of returned Documents inside a group using Graphql

Hi there,

I have a Category type that the users can add as many documents of Article type as they want.
And I'm trying to get a category type and its linked Article documents using this function:

    const result = await client.getAllByType("category", {
        orderings: [
            { field: "my.category.publishDate", direction: "desc" },
            { field: "document.first_publication_date", direction: "desc" },
        ], 
        filters: [
            prismic.filter.at("my.category.uid", params.uid)
        ],
        graphQuery: `
            {
                category {
                    name
                    group {
                        article {
                            title
                            publishDate
                            featuredImage
                            slices
                            meta_title
                            meta_description
                            meta_image
                        }
                    }
                }
            }
        `,        
    })

So my question is, are there any way I can implement pagination for the article documents inside the group of the Category type?

Hey Will,

I would love to know a little more about your use case!

Based on your code, I assume that you have created a category page (example /travel) and you have articles that appear in that category (example /travel/visit-bahamas).

It looks like you're modeling this relationship by linking the article from the category. If that's correct, it's really the inverse of our recommended implementation. Here you can see how we recommend creating categories:

There, we recommend linking to the category from the article. Then, on your category page, you can query all articles that link to that category.

Having said that, the implementation you've created looks like it might create problems. The group field can't have infinite documents. At a certain point, your document could get too big and your queries will fail. That's because — as you have noticed — there is no way to paginate a group field.

I hope that makes sense! Let me know if you have any questions.

Sam

1 Like

Ah I see, thank you Sam. Might have missed this article.