Skip to content

Commit e1076af

Browse files
rajzikjan.silhanfabien0102
authored
feat!: Support react-query v5 (use object signatures) #179
* initial implementation * copy test * update tests and add export * Update readme for V5 generator * change rq component generator to object * Use npm in ci --------- Co-authored-by: jan.silhan <[email protected]> Co-authored-by: Fabien BERNARD <[email protected]>
1 parent 23ed5ed commit e1076af

File tree

3 files changed

+163
-115
lines changed

3 files changed

+163
-115
lines changed

.github/workflows/tests.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: Tests
2-
3-
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
8-
types:
9-
- opened
10-
- synchronize
11-
- reopened
12-
13-
jobs:
14-
test:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- uses: actions/checkout@v1
18-
- uses: actions/setup-node@v1
19-
with:
20-
node-version: 16.13.1
21-
- run: yarn
22-
- run: yarn test
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v1
18+
- uses: actions/setup-node@v1
19+
with:
20+
node-version: 18.10.0
21+
- run: npm ci
22+
- run: npm test

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

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ describe("generateReactQueryComponents", () => {
109109
/**
110110
* Get all the pets
111111
*/
112-
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal), {
112+
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
113+
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
114+
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
113115
...options,
114116
...queryOptions
115117
}); };
@@ -231,7 +233,9 @@ describe("generateReactQueryComponents", () => {
231233
/**
232234
* Get all the pets
233235
*/
234-
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal), {
236+
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
237+
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
238+
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
235239
...options,
236240
...queryOptions
237241
}); };
@@ -357,7 +361,9 @@ describe("generateReactQueryComponents", () => {
357361
/**
358362
* Get all the pets
359363
*/
360-
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal), {
364+
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
365+
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
366+
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
361367
...options,
362368
...queryOptions
363369
}); };
@@ -454,7 +460,9 @@ describe("generateReactQueryComponents", () => {
454460
/**
455461
* Get all the pets
456462
*/
457-
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal), {
463+
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
464+
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
465+
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
458466
...options,
459467
...queryOptions
460468
}); };
@@ -586,7 +594,10 @@ describe("generateReactQueryComponents", () => {
586594
587595
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, \\"mutationFn\\">) => {
588596
const { fetcherOptions } = usePetstoreContext();
589-
return reactQuery.useMutation<string, AddPetError, AddPetVariables>((variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }), options);
597+
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
598+
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
599+
...options
600+
});
590601
};
591602
592603
export type QueryOperation = {
@@ -717,7 +728,10 @@ describe("generateReactQueryComponents", () => {
717728
718729
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, \\"mutationFn\\">) => {
719730
const { fetcherOptions } = usePetstoreContext();
720-
return reactQuery.useMutation<string, AddPetError, AddPetVariables>((variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }), options);
731+
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
732+
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
733+
...options
734+
});
721735
};
722736
723737
export type QueryOperation = {
@@ -848,7 +862,10 @@ describe("generateReactQueryComponents", () => {
848862
849863
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, \\"mutationFn\\">) => {
850864
const { fetcherOptions } = usePetstoreContext();
851-
return reactQuery.useMutation<string, AddPetError, AddPetVariables>((variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }), options);
865+
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
866+
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
867+
...options
868+
});
852869
};
853870
854871
export type QueryOperation = {
@@ -957,7 +974,10 @@ describe("generateReactQueryComponents", () => {
957974
958975
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
959976
const { fetcherOptions } = usePetstoreContext();
960-
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
977+
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
978+
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
979+
...options
980+
});
961981
};
962982
963983
export type QueryOperation = {
@@ -1066,7 +1086,10 @@ describe("generateReactQueryComponents", () => {
10661086
10671087
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
10681088
const { fetcherOptions } = usePetstoreContext();
1069-
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
1089+
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
1090+
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
1091+
...options
1092+
});
10701093
};
10711094
10721095
export type QueryOperation = {
@@ -1175,7 +1198,10 @@ describe("generateReactQueryComponents", () => {
11751198
11761199
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
11771200
const { fetcherOptions } = useContext();
1178-
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
1201+
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
1202+
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
1203+
...options
1204+
});
11791205
};
11801206
11811207
export type QueryOperation = {
@@ -1271,7 +1297,9 @@ describe("generateReactQueryComponents", () => {
12711297
/**
12721298
* Get all the pets
12731299
*/
1274-
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal), {
1300+
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
1301+
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
1302+
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
12751303
...options,
12761304
...queryOptions
12771305
}); };

0 commit comments

Comments
 (0)