Skip to content

Commit

Permalink
feat!: Support react-query v5 (use object signatures) #179
Browse files Browse the repository at this point in the history
* 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 <jan.silhan@pwc.com>
Co-authored-by: Fabien BERNARD <fabien0102@gmail.com>
  • Loading branch information
3 people committed Jul 2, 2023
1 parent 23ed5ed commit e1076af
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 115 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: Tests

on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 16.13.1
- run: yarn
- run: yarn test
name: Tests

on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 18.10.0
- run: npm ci
- run: npm test
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
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), {
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>({
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -231,7 +233,9 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
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), {
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>({
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -357,7 +361,9 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
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), {
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>({
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -454,7 +460,9 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
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), {
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>({
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -586,7 +594,10 @@ describe("generateReactQueryComponents", () => {
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, \\"mutationFn\\">) => {
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, AddPetError, AddPetVariables>((variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }), options);
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
...options
});
};
export type QueryOperation = {
Expand Down Expand Up @@ -717,7 +728,10 @@ describe("generateReactQueryComponents", () => {
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, \\"mutationFn\\">) => {
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, AddPetError, AddPetVariables>((variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }), options);
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
...options
});
};
export type QueryOperation = {
Expand Down Expand Up @@ -848,7 +862,10 @@ describe("generateReactQueryComponents", () => {
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, \\"mutationFn\\">) => {
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, AddPetError, AddPetVariables>((variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }), options);
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
...options
});
};
export type QueryOperation = {
Expand Down Expand Up @@ -957,7 +974,10 @@ describe("generateReactQueryComponents", () => {
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
});
};
export type QueryOperation = {
Expand Down Expand Up @@ -1066,7 +1086,10 @@ describe("generateReactQueryComponents", () => {
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
});
};
export type QueryOperation = {
Expand Down Expand Up @@ -1175,7 +1198,10 @@ describe("generateReactQueryComponents", () => {
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
const { fetcherOptions } = useContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
});
};
export type QueryOperation = {
Expand Down Expand Up @@ -1271,7 +1297,9 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
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), {
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>({
queryKey: queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }),
queryFn: ({ signal }) => fetchListPets({ ...fetcherOptions, ...variables }, signal),
...options,
...queryOptions
}); };
Expand Down

0 comments on commit e1076af

Please sign in to comment.