Delveroff
Delveroff•5mo ago

Wrong types for `PaginationResult`

continueCursor should be string | null, now it's just string
import type { PaginationResult } from 'convex/server'
import { describe, expect, it } from 'vitest'
import { convexTester } from '~/convex/utils/setup.testing'
import { api } from '../_generated/api'
import type { Doc, Id } from '../_generated/dataModel'

describe.concurrent.only('posts', () => {
it('should return empty collection on no data', async () => {
const t = convexTester()
expect(
await t.query(api.user.posts.default, {
userId: '1;users' as Id<'users'>,
cursor: null,
}),
).toEqual({
// @ts-expect-error the tests passes, therefore, the value is null
continueCursor: null,
isDone: true,
page: [],
} satisfies PaginationResult<Doc<'posts'>>)
})
})
import type { PaginationResult } from 'convex/server'
import { describe, expect, it } from 'vitest'
import { convexTester } from '~/convex/utils/setup.testing'
import { api } from '../_generated/api'
import type { Doc, Id } from '../_generated/dataModel'

describe.concurrent.only('posts', () => {
it('should return empty collection on no data', async () => {
const t = convexTester()
expect(
await t.query(api.user.posts.default, {
userId: '1;users' as Id<'users'>,
cursor: null,
}),
).toEqual({
// @ts-expect-error the tests passes, therefore, the value is null
continueCursor: null,
isDone: true,
page: [],
} satisfies PaginationResult<Doc<'posts'>>)
})
})
Maybe it's just testing behavior. If it is, then there's a bug in convex-test.
7 Replies
Delveroff
DelveroffOP•5mo ago
Oh, I forgot to mention that I don't want to "leak" numItems, so I only pass the cursor:
import { v } from 'convex/values'
import { query } from '../_generated/server'

export default query({
args: {
cursor: v.union(v.string(), v.null()),
usersId: v.id('users'),
},
handler: async (ctx, { cursor, userId }) =>
await ctx.db.query('posts').withIndex('by_slug').order('desc').paginate({
numItems: 20,
cursor,
}),
})
import { v } from 'convex/values'
import { query } from '../_generated/server'

export default query({
args: {
cursor: v.union(v.string(), v.null()),
usersId: v.id('users'),
},
handler: async (ctx, { cursor, userId }) =>
await ctx.db.query('posts').withIndex('by_slug').order('desc').paginate({
numItems: 20,
cursor,
}),
})
ian
ian•5mo ago
continueCursor is not the cursor passed in, it's a string returned from .paginate so it shouldn't be null - if you're seeing null come back I expect it's a bug in convex-test - if that's the case can you file an issue on https://github.com/get-convex/convex-auth/issues ?
GitHub
Issues · get-convex/convex-auth
Library for built-in auth. Contribute to get-convex/convex-auth development by creating an account on GitHub.
Delveroff
DelveroffOP•5mo ago
GitHub
Wrong types for PaginationResult · Issue #16 · get-convex/convex-...
From Discord continueCursor should be string | null, now it's just string import type { PaginationResult } from 'convex/server' import { describe, expect, it } from 'vitest' imp...
ian
ian•5mo ago
Technically, the issue is not that the type is wrong, the result should never be null. It sounds like the issue is Convex test might return null
RJ
RJ•4mo ago
Just ran into this myself and lost time tracking it down to a convex-test issue, then opened a duplicate issue of the one posted by Delveroff 😅 Would be nice to have this fixed! As noted here, I think the issue is just that we break before assigning a value to continueCursor when isDone is truthy. If I'm right, it should be trivial to fix the issue when there are greater than zero items in the result set. If there are zero, I'm guessing we'd need to produce some kind of dummy cursor value.
lee
lee•4mo ago
should be fixed now thanks for the report 🥇
RJ
RJ•4mo ago
Upgraded, confirmed fixed

Did you find this page helpful?