feat: add count operation to collections (#5930)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user