Custom GraphQL Resolver with Pagination Strapi v4

Hey there,

So I’m trying to get a collection type (in this case, called “alerts” and a custom resolver called “GetMyAlerts”) with pagination.

I’ve sort’ve got something going, it takes in a pagination arg and returns the collection data with toEntityResponseCollection, which I thought might magically transform pagination somehow, but alas, I’m not sure where to go from here.

          type: "Query",
          definition(t) {
            t.field("getMyAlerts", {

              type: "AlertEntityResponseCollection",
              args: {
                pagination: nexus.arg({ type: "PaginationArg" }),

              resolve: async (parent, args, ctx) => {
                const { toEntityResponseCollection } = strapi

                let alerts = await strapi.entityService.findMany(
                    filters: {
                    sort: [
                        createdAt: "desc",
                    limit: args.pagination.pageSize,

                let returnTo = toEntityResponseCollection(alerts, {
                  args: args,
                  resourceUID: "api::alert.alert",

                return returnTo;

Any ideas or could you point me in the right direction?

1 Like