Merge pull request #17143 from strapi/fix/16170-graphql-pagination-count-filter

This commit is contained in:
Jean-Sébastien Herbaux 2023-07-03 11:10:05 +02:00 committed by GitHub
commit 17bf13c6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

View File

@ -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 */ `

View File

@ -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);