Hi folks, general question for you all about pagi...
# orm-help
j
Hi folks, general question for you all about pagination. Has anyone here implemented nested pagination in GraphQL land? Something like
Copy code
usersPagination(filter: { search, count, sort }) {
    users {
        username
        email
        etc
    }
    pageInfo {
        count
        pageIndex
    }
    postsPagination(filterForParent: {search, startDate }) <- another filter {
        posts {
            pages
        }
        pageInfo {
            count
            pageIndex
        }
    }
}
In theory, we are trying to see if it is possible to define some filter on a child, and use that filter in the parent? So that we can define for instance "Give me 10 users, who contain
search
, or if their posts contain
search
. Just give me 10 in total" Any clean API's that do something like this?
r
The GraphQL query provided above would perform filters separately. I think as per your request statement:
Give me 10 users, who contain 
search
, or if their posts contain 
search
.
You would need to implement a custom resolver with a query like this:
Copy code
prisma.user.findMany({
    where: {
      OR: [
        { name: { contains: 'search' } },
        { posts: { some: { title: { contains: 'search' } } } },
      ],
    },
    take: 10,
  })
j
Hey Ryan! Indeed, you are right. I was thinking of defining a specific filter args , that can be found by the parent ‘filterForParent:{ parentName, otherFilters }’, and the parent could look into the ‘info’ resolver args to see if any child resolver has extra filter attributes (and if so, whether these children have a matching nested prisma filter this parent could use in its final query). Though Im not sure if this is considered bad practice in the context of graphql
💯 1
=> this would lead to being able to define your pagination logic from graphql (for supported child-parent resolvers).
r
Your approach is absolutely fine, as that’s the exact case in which I would use the
info
argument. You can easily fetch for the filter attributes and add them to the query dynamically 🙂
🙌 1
j
Absolute legend, thanks for the sanity check Ryan :)
💯 1
🙌 1