Skip to content

Commit 38360f1

Browse files
authored
Merge pull request #943 from devoxa/fix-generics-with-number-id
Add regression test for number id generics
2 parents 437a2ce + 7f7b759 commit 38360f1

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

tests/__snapshots__/index.spec.ts.snap

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,77 @@ exports[`prisma-relay-cursor-connection number id returns all users 1`] = `
21452145
}
21462146
`;
21472147

2148+
exports[`prisma-relay-cursor-connection number id returns the first 5 completed todos 1`] = `
2149+
{
2150+
"edges": [
2151+
{
2152+
"cursor": 1,
2153+
"node": {
2154+
"email": "[email protected]",
2155+
"id": 1,
2156+
},
2157+
},
2158+
{
2159+
"cursor": 2,
2160+
"node": {
2161+
"email": "[email protected]",
2162+
"id": 2,
2163+
},
2164+
},
2165+
{
2166+
"cursor": 3,
2167+
"node": {
2168+
"email": "[email protected]",
2169+
"id": 3,
2170+
},
2171+
},
2172+
{
2173+
"cursor": 4,
2174+
"node": {
2175+
"email": "[email protected]",
2176+
"id": 4,
2177+
},
2178+
},
2179+
{
2180+
"cursor": 5,
2181+
"node": {
2182+
"email": "[email protected]",
2183+
"id": 5,
2184+
},
2185+
},
2186+
],
2187+
"nodes": [
2188+
{
2189+
"email": "[email protected]",
2190+
"id": 1,
2191+
},
2192+
{
2193+
"email": "[email protected]",
2194+
"id": 2,
2195+
},
2196+
{
2197+
"email": "[email protected]",
2198+
"id": 3,
2199+
},
2200+
{
2201+
"email": "[email protected]",
2202+
"id": 4,
2203+
},
2204+
{
2205+
"email": "[email protected]",
2206+
"id": 5,
2207+
},
2208+
],
2209+
"pageInfo": {
2210+
"endCursor": 5,
2211+
"hasNextPage": true,
2212+
"hasPreviousPage": false,
2213+
"startCursor": 1,
2214+
},
2215+
"totalCount": 20,
2216+
}
2217+
`;
2218+
21482219
exports[`prisma-relay-cursor-connection number id returns the first 5 users 1`] = `
21492220
{
21502221
"edges": [

tests/index.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,39 @@ describe('prisma-relay-cursor-connection', () => {
184184

185185
expect(result).toMatchSnapshot()
186186
})
187+
188+
test('returns the first 5 completed todos', async () => {
189+
const baseArgs = {
190+
select: { id: true, email: true },
191+
where: { email: { contains: '@email' } },
192+
}
193+
194+
const result = await findManyCursorConnection<User, { id: number }>(
195+
(args) => client.user.findMany({ ...args, ...baseArgs }),
196+
() => client.user.count({ where: baseArgs.where }),
197+
{ first: 5 }
198+
)
199+
200+
expect(result).toMatchSnapshot()
201+
202+
// Test that the return types work via TS
203+
result.edges[0].node.email
204+
205+
// @ts-expect-error Typo in selected field
206+
result.edges[0].node.emmail
207+
208+
// @ts-expect-error Not selected field
209+
result.edges[0].node.text
210+
211+
// Test that the return types work via TS
212+
result.nodes[0].email
213+
214+
// @ts-expect-error Typo in selected field
215+
result.nodes[0].emmail
216+
217+
// @ts-expect-error Not selected field
218+
result.nodes[0].text
219+
})
187220
})
188221

189222
describe('unique field', () => {

0 commit comments

Comments
 (0)