Strapi V4 handle pagination in GraphQL custom resolver

Posting this, as it took a little bit to get a working solution still, create a custom resolver in /src/api/index.js

          pages: {
            resolve: async (obj, options, ctx) => {
              const { toEntityResponseCollection } = strapi.service(
                "plugin::graphql.format"
              ).returnTypes;

              const data = await strapi.service(
                "api::page.page"
              ).find(options);
              const start = options.start || 0;
              const limit = options.limit || 100;
              const response = toEntityResponseCollection(data.results, {
                args: { start, limit },
                resourceUID: "api::page.page",
              })
              return response;
            },
          },```
This is using the find service, which you can edit or extend. With this resolver you can pass in logic to that service and also get the meta data and pagination.
1 Like