Skip to content

Commit 450b069

Browse files
needimfabien0102
andauthored
feat!: Implement query cancellation in react-query generated components (#95)
* fix: package-lock * chore: abort signal * fix: package-lock files * Revert test command * Fix AbortSignal flow Separate `signal` from the context since this is not overridable in user land. * Pass signals on fetcher without variables Co-authored-by: Fabien BERNARD <[email protected]>
1 parent fa78341 commit 450b069

File tree

9 files changed

+3213
-16242
lines changed

9 files changed

+3213
-16242
lines changed

cli/package-lock.json

Lines changed: 0 additions & 13729 deletions
This file was deleted.

package-lock.json

Lines changed: 3148 additions & 2300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eslint": "^8.0.1",
2727
"eslint-config-prettier": "^8.3.0",
2828
"eslint-plugin-prettier": "^4.0.0",
29+
"got": "^12.4.1",
2930
"husky": "^7.0.2",
3031
"jest": "^27.2.5",
3132
"lerna": "^5.5.0",

plugins/typescript/package-lock.json

Lines changed: 0 additions & 191 deletions
This file was deleted.

plugins/typescript/src/core/createOperationFetcherFnNodes.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,27 @@ export const createOperationFetcherFnNodes = ({
6161
variablesType,
6262
undefined
6363
),
64+
f.createParameterDeclaration(
65+
undefined,
66+
undefined,
67+
f.createIdentifier("signal"),
68+
f.createToken(ts.SyntaxKind.QuestionToken),
69+
f.createTypeReferenceNode(
70+
f.createIdentifier("AbortSignal")
71+
)
72+
),
6473
]
65-
: [],
74+
: [
75+
f.createParameterDeclaration(
76+
undefined,
77+
undefined,
78+
f.createIdentifier("signal"),
79+
f.createToken(ts.SyntaxKind.QuestionToken),
80+
f.createTypeReferenceNode(
81+
f.createIdentifier("AbortSignal")
82+
)
83+
),
84+
],
6685
undefined,
6786
f.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
6887
f.createCallExpression(
@@ -91,8 +110,15 @@ export const createOperationFetcherFnNodes = ({
91110
f.createSpreadAssignment(
92111
f.createIdentifier("variables")
93112
),
113+
f.createShorthandPropertyAssignment(
114+
f.createIdentifier("signal")
115+
),
94116
]
95-
: []),
117+
: [
118+
f.createShorthandPropertyAssignment(
119+
f.createIdentifier("signal")
120+
),
121+
]),
96122
],
97123
false
98124
),

plugins/typescript/src/generators/generateFetchers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("generateFetchers", () => {
9696
/**
9797
* Get all the pets
9898
*/
99-
export const listPets = () => petstoreFetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\" });
99+
export const listPets = (signal?: AbortSignal) => petstoreFetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\", signal });
100100
"
101101
`);
102102
});
@@ -140,7 +140,7 @@ describe("generateFetchers", () => {
140140
/**
141141
* Get all the pets
142142
*/
143-
export const listPets = () => fetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\" });
143+
export const listPets = (signal?: AbortSignal) => fetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\", signal });
144144
"
145145
`);
146146
});
@@ -193,7 +193,7 @@ describe("generateFetchers", () => {
193193
/**
194194
* Get all the pets
195195
*/
196-
export const listPets = (variables: ListPetsVariables) => petstoreFetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\", ...variables });
196+
export const listPets = (variables: ListPetsVariables, signal?: AbortSignal) => petstoreFetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\", ...variables, signal });
197197
"
198198
`);
199199
});
@@ -243,7 +243,7 @@ describe("generateFetchers", () => {
243243
/**
244244
* Get all the pets
245245
*/
246-
export const listPets = () => petstoreFetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\" });
246+
export const listPets = (signal?: AbortSignal) => petstoreFetch<ListPetsResponse, ListPetsError, undefined, {}, {}, {}>({ url: \\"/pets\\", method: \\"get\\", signal });
247247
248248
export const operationsByTag = { \\"pets\\": { listPets } };
249249
"

0 commit comments

Comments
 (0)