Skip to content

Commit 48d1db3

Browse files
authored
Add missing unit test for #71 (#73)
1 parent 571abf5 commit 48d1db3

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

packages/auto-pagination/__tests__/auto-pagination.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeExecutableSchema } from '@graphql-tools/schema'
22
import { wrapSchema } from '@graphql-tools/wrap'
3-
import { execute, graphql, parse } from 'graphql'
3+
import { execute, ExecutionResult, parse } from 'graphql'
44
import AutoPaginationTransform from '../src'
55

66
describe('Auto Pagination', () => {
@@ -9,12 +9,19 @@ describe('Auto Pagination', () => {
99
const schema = makeExecutableSchema({
1010
typeDefs: /* GraphQL */ `
1111
type Query {
12+
_meta: Meta
1213
users(first: Int = ${LIMIT}, skip: Int = 0): [User!]!
1314
}
1415
type User {
1516
id: ID!
1617
name: String!
1718
}
19+
type Meta {
20+
block: Block
21+
}
22+
type Block {
23+
number: Int
24+
}
1825
`,
1926
resolvers: {
2027
Query: {
@@ -24,6 +31,11 @@ describe('Auto Pagination', () => {
2431
}
2532
return users.slice(skip, skip + first)
2633
},
34+
_meta: () => ({
35+
block: {
36+
number: Date.now(),
37+
},
38+
}),
2739
},
2840
},
2941
})
@@ -85,4 +97,26 @@ describe('Auto Pagination', () => {
8597
expect(result.data?.users).toHaveLength(2)
8698
expect(result.data?.users).toEqual(users.slice(2, 4))
8799
})
100+
it('should ignore non entity fields added by other transforms', async () => {
101+
const query = /* GraphQL */ `
102+
query {
103+
_meta {
104+
block {
105+
number
106+
}
107+
}
108+
users(first: 10) {
109+
id
110+
name
111+
}
112+
}
113+
`
114+
const result: ExecutionResult<any> = await execute({
115+
schema: wrappedSchema,
116+
document: parse(query),
117+
})
118+
expect(result.data?._meta?.block?.number).toBeDefined()
119+
expect(result.data?.users).toHaveLength(10)
120+
expect(result.data?.users).toEqual(users.slice(0, 10))
121+
})
88122
})

0 commit comments

Comments
 (0)