feat: add count operation to collections (#5930)

This commit is contained in:
Ritsu
2024-04-20 21:45:44 +03:00
committed by GitHub
parent d987e5628a
commit d5cbbc472d
25 changed files with 538 additions and 9 deletions

View File

@@ -116,6 +116,20 @@ describe('collections-graphql', () => {
expect(docs).toContainEqual(expect.objectContaining({ id: existingDoc.id }))
})
it('should count', async () => {
const query = `query {
countPosts {
totalDocs
}
}`
const { data } = await restClient
.GRAPHQL_POST({ body: JSON.stringify({ query }) })
.then((res) => res.json())
const { totalDocs } = data.countPosts
expect(typeof totalDocs).toBe('number')
})
it('should read using multiple queries', async () => {
const query = `query {
postIDs: Posts {
@@ -848,6 +862,21 @@ describe('collections-graphql', () => {
expect(docs[0].relationToCustomID.id).toStrictEqual(1)
})
it('should query on relationships with custom IDs - count', async () => {
const query = `query {
countPosts(where: { title: { equals: "has custom ID relation" }}) {
totalDocs
}
}`
const { data } = await restClient
.GRAPHQL_POST({ body: JSON.stringify({ query }) })
.then((res) => res.json())
const { totalDocs } = data.countPosts
expect(totalDocs).toStrictEqual(1)
})
it('should query a document with a deleted relationship', async () => {
const relation = await payload.create({
collection: relationSlug,