diff --git a/api-tests/plugins/graphql/crud.test.api.js b/api-tests/plugins/graphql/crud.test.api.js index 1c479433e5..13c85de3c1 100644 --- a/api-tests/plugins/graphql/crud.test.api.js +++ b/api-tests/plugins/graphql/crud.test.api.js @@ -243,6 +243,58 @@ describe('Test Graphql API End to End', () => { }); }); + test('Pagination counts are correct', async () => { + const res = await graphqlQuery({ + query: /* GraphQL */ ` + { + posts(filters: { name: { eq: "post 2" } }) { + data { + id + attributes { + name + bigint + nullable + category + } + } + meta { + pagination { + total + pageSize + page + pageCount + } + } + } + } + `, + }); + + const expectedPost = data.posts[1]; + + expect(res.statusCode).toBe(200); + expect(res.body).toEqual({ + data: { + posts: { + data: [ + { + id: expectedPost.id, + attributes: omit('id', expectedPost), + }, + ], + meta: { + pagination: { + total: 1, + pageSize: 10, + page: 1, + pageCount: 1, + }, + }, + }, + }, + }); + }); + test.skip('List posts with `createdBy` and `updatedBy`', async () => { const res = await graphqlQuery({ query: /* GraphQL */ ` diff --git a/packages/plugins/graphql/server/services/internals/types/response-collection-meta.js b/packages/plugins/graphql/server/services/internals/types/response-collection-meta.js index d7310ae456..72555aa9b2 100644 --- a/packages/plugins/graphql/server/services/internals/types/response-collection-meta.js +++ b/packages/plugins/graphql/server/services/internals/types/response-collection-meta.js @@ -25,8 +25,9 @@ module.exports = ({ strapi }) => { const { args, resourceUID } = parent; const { start, limit } = args; const safeLimit = Math.max(limit, 1); + const contentType = strapi.getModel(resourceUID); - const sanitizedQuery = await sanitize.contentAPI.query(args, parent.contentType, { + const sanitizedQuery = await sanitize.contentAPI.query(args, contentType, { auth: ctx?.state?.auth, }); const total = await strapi.entityService.count(resourceUID, sanitizedQuery);