Skip to content

Commit 82620eb

Browse files
committed
chore(e2e): add TanStack Query <= v5.79.2 tests
1 parent 0346ac1 commit 82620eb

4 files changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/package-lock.json
2+
node_modules
3+
/src/api
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "typescript-nodenext-nodenext-tanstack-query-5-79-2",
3+
"description": "This test verifies that the current version of OpenAPI Qraft is compatible with TanStack Query 5.79.2 or earlier, due to the removal of TQueryData for UseSuspenseInfiniteQueryOptions in TanStack Query 5.80.0",
4+
"private": true,
5+
"version": "1.0.0",
6+
"main": "dist/index.js",
7+
"type": "module",
8+
"scripts": {
9+
"build": "tsc",
10+
"codegen": "openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript https://raw.githubusercontent.com/swagger-api/swagger-petstore/7767363b841961221a38c0be9c6b1066a5120051/src/main/resources/openapi.yaml --clean -o src/api --openapi-types-import-path '../schema.js' --explicit-import-extensions --openapi-types-file-name schema.ts",
11+
"e2e:pre-build": "npm run codegen",
12+
"e2e:post-build": "node ./dist/index.js"
13+
},
14+
"dependencies": {
15+
"@openapi-qraft/cli": "latest",
16+
"@openapi-qraft/react": "latest",
17+
"@tanstack/react-query": "5.79.2",
18+
"@tanstack/query-core": "5.79.2",
19+
"@types/node": "latest",
20+
"typescript": "latest"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/OpenAPI-Qraft/openapi-qraft.git"
25+
}
26+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import type { components, paths } from './api/index.js';
2+
import { requestFn } from '@openapi-qraft/react';
3+
import * as callbacksIndex from '@openapi-qraft/react/callbacks';
4+
import * as callbacks from '@openapi-qraft/react/callbacks/index';
5+
import { useMutation } from '@openapi-qraft/react/callbacks/useMutation';
6+
import { useQuery } from '@openapi-qraft/react/callbacks/useQuery';
7+
import {
8+
createSecureRequestFn,
9+
QraftSecureRequestFn,
10+
} from '@openapi-qraft/react/Unstable_QraftSecureRequestFn';
11+
import { QueryClient } from '@tanstack/react-query';
12+
import { createAPIClient as createAPIClientMjs } from './api/index.js';
13+
14+
console.log({} satisfies Partial<components>);
15+
console.log({} satisfies Partial<paths>);
16+
17+
if (typeof createAPIClientMjs !== 'undefined') {
18+
console.log('Client is imported successfully from esm project.');
19+
} else {
20+
console.error('Client is not imported from esm project.');
21+
process.exit(1);
22+
}
23+
24+
if (typeof callbacks !== 'undefined') {
25+
console.log('Callbacks are imported successfully from esm project.');
26+
} else {
27+
console.error('Callbacks are not imported from esm project.');
28+
process.exit(1);
29+
}
30+
31+
if (typeof callbacksIndex !== 'undefined') {
32+
console.log('Callbacks index is imported successfully from esm project.');
33+
} else {
34+
console.error('Callbacks index is not imported from esm project.');
35+
process.exit(1);
36+
}
37+
38+
if (typeof useMutation !== 'undefined') {
39+
console.log('useMutation is imported successfully from esm project.');
40+
} else {
41+
console.error('useMutation is not imported from esm project.');
42+
process.exit(1);
43+
}
44+
45+
if (typeof useQuery !== 'undefined') {
46+
console.log('useQuery is imported successfully from esm project.');
47+
} else {
48+
console.error('useQuery is not imported from esm project.');
49+
process.exit(1);
50+
}
51+
52+
if (typeof createSecureRequestFn !== 'undefined') {
53+
console.log(
54+
'createSecureRequestFn is imported successfully from esm project.'
55+
);
56+
} else {
57+
console.error('createSecureRequestFn is not imported from esm project.');
58+
process.exit(1);
59+
}
60+
61+
if (typeof QraftSecureRequestFn !== 'undefined') {
62+
console.log(
63+
'QraftSecureRequestFn is imported successfully from esm project.'
64+
);
65+
} else {
66+
console.error('QraftSecureRequestFn is not imported from esm project.');
67+
process.exit(1);
68+
}
69+
70+
function useTsCheck() {
71+
const client = createAPIClientMjs({
72+
baseUrl: 'https://api.example.com',
73+
queryClient: new QueryClient(),
74+
requestFn,
75+
});
76+
77+
const query = client.pet.findPetsByStatus.useSuspenseInfiniteQuery(
78+
{},
79+
{
80+
initialPageParam: {
81+
query: {
82+
status: 'sold',
83+
},
84+
},
85+
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => {
86+
// @ts-expect-error - should not be never or any
87+
lastPageParam.query?.status satisfies never;
88+
lastPageParam.query?.status satisfies
89+
| undefined
90+
| 'sold'
91+
| 'available'
92+
| 'pending';
93+
94+
return lastPageParam.query?.status === 'sold'
95+
? {
96+
query: {
97+
status: 'sold',
98+
},
99+
}
100+
: undefined;
101+
},
102+
}
103+
);
104+
105+
query.data.pages[0] satisfies typeof client.pet.findPetsByStatus.types.data;
106+
// @ts-expect-error - should not be never or any
107+
query.data.pages[0] satisfies never;
108+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist",
4+
"rootDir": "./src",
5+
"target": "es2016",
6+
"module": "NodeNext",
7+
"moduleResolution": "NodeNext",
8+
"esModuleInterop": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"strict": true,
11+
"skipLibCheck": true,
12+
"verbatimModuleSyntax": true
13+
}
14+
}

0 commit comments

Comments
 (0)