mirror of
https://github.com/strapi/strapi.git
synced 2025-08-14 03:34:53 +00:00
Merge pull request #17143 from strapi/fix/16170-graphql-pagination-count-filter
This commit is contained in:
commit
17bf13c6b2
@ -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 () => {
|
test.skip('List posts with `createdBy` and `updatedBy`', async () => {
|
||||||
const res = await graphqlQuery({
|
const res = await graphqlQuery({
|
||||||
query: /* GraphQL */ `
|
query: /* GraphQL */ `
|
||||||
|
@ -25,8 +25,9 @@ module.exports = ({ strapi }) => {
|
|||||||
const { args, resourceUID } = parent;
|
const { args, resourceUID } = parent;
|
||||||
const { start, limit } = args;
|
const { start, limit } = args;
|
||||||
const safeLimit = Math.max(limit, 1);
|
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,
|
auth: ctx?.state?.auth,
|
||||||
});
|
});
|
||||||
const total = await strapi.entityService.count(resourceUID, sanitizedQuery);
|
const total = await strapi.entityService.count(resourceUID, sanitizedQuery);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user