Skip to content

Commit 25d2c8f

Browse files
authored
test(graphql): add TypedDocumentNode inference tests (#2018)
1 parent 5c676b8 commit 25d2c8f

File tree

3 files changed

+73
-31
lines changed

3 files changed

+73
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
"devDependencies": {
260260
"@commitlint/cli": "^18.4.4",
261261
"@commitlint/config-conventional": "^18.4.4",
262+
"@graphql-typed-document-node/core": "^3.2.0",
262263
"@fastify/websocket": "^8.3.1",
263264
"@open-draft/test-server": "^0.4.2",
264265
"@ossjs/release": "^0.8.1",

pnpm-lock.yaml

Lines changed: 29 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { graphql, HttpResponse } from 'msw'
2+
import { TypedDocumentNode } from '@graphql-typed-document-node/core'
3+
4+
const GetUserQuery = {} as TypedDocumentNode<
5+
{
6+
user: {
7+
name: 'John'
8+
}
9+
},
10+
{ userId: string }
11+
>
12+
13+
graphql.query(GetUserQuery, ({ variables }) => {
14+
variables.userId.toUpperCase()
15+
16+
return HttpResponse.json({
17+
data: {
18+
user: { name: 'John' },
19+
},
20+
})
21+
})
22+
23+
graphql.query(GetUserQuery, ({ variables }) => {
24+
// @ts-expect-error Unknown variable
25+
variables.unknownVariable
26+
27+
return HttpResponse.json({
28+
data: {
29+
user: { name: 'John' },
30+
},
31+
})
32+
})
33+
34+
graphql.query(GetUserQuery, () => {
35+
return HttpResponse.json({
36+
data: {
37+
user: {
38+
// @ts-expect-error Invalid response type.
39+
name: 123,
40+
},
41+
},
42+
})
43+
})

0 commit comments

Comments
 (0)