Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Use query option pattern and support useSuspense #263

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert name change
jan.silhan committed Jan 21, 2025
commit 6831a6af514c1774a4ab61bba0fa902065ffe7fb
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as Schemas from "./petstoreSchemas";
@@ -128,7 +128,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -137,7 +137,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -334,7 +334,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as Schemas from "./petstoreSchemas";
@@ -385,7 +385,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -394,7 +394,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -615,7 +615,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as Schemas from "./petstoreSchemas";
@@ -662,7 +662,7 @@ describe("generateReactQueryComponents", () => {
/**
* Info for a specific pet
*/
export const useSuspenseShowPetById = <TData = ShowPetByIdResponse>(variables: ShowPetByIdVariables, options?: Omit<reactQuery.UseQueryOptions<ShowPetByIdResponse, ShowPetByIdError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useSuspenseQuery<ShowPetByIdResponse, ShowPetByIdError, TData>({
export const useSuspenseShowPetById = <TData = ShowPetByIdResponse>(variables: ShowPetByIdVariables, options?: Omit<reactQuery.UseQueryOptions<ShowPetByIdResponse, ShowPetByIdError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useSuspenseQuery<ShowPetByIdResponse, ShowPetByIdError, TData>({
...showPetByIdQuery(variables),
...options,
...queryOptions
@@ -671,7 +671,7 @@ describe("generateReactQueryComponents", () => {
/**
* Info for a specific pet
*/
export const useShowPetById = <TData = ShowPetByIdResponse>(variables: ShowPetByIdVariables, options?: Omit<reactQuery.UseQueryOptions<ShowPetByIdResponse, ShowPetByIdError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useQuery<ShowPetByIdResponse, ShowPetByIdError, TData>({
export const useShowPetById = <TData = ShowPetByIdResponse>(variables: ShowPetByIdVariables, options?: Omit<reactQuery.UseQueryOptions<ShowPetByIdResponse, ShowPetByIdError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useQuery<ShowPetByIdResponse, ShowPetByIdError, TData>({
...showPetByIdQuery(variables),
...options,
...queryOptions
@@ -890,7 +890,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as Schemas from "./petstoreSchemas";
@@ -945,7 +945,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -954,7 +954,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -1033,7 +1033,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as Schemas from "./petstoreSchemas";
@@ -1071,7 +1071,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -1080,7 +1080,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -1186,7 +1186,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
@@ -1212,7 +1212,7 @@ describe("generateReactQueryComponents", () => {
export const fetchAddPet = (variables: AddPetVariables, signal?: AbortSignal) => petstoreFetch<string, AddPetError, AddPetRequestBody, {}, {}, {}>({ url: "/pet", method: "post", ...variables, signal });
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, "mutationFn">) => {
const { fetcherOptions } = getPetstoreContext();
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
...options
@@ -1320,7 +1320,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
@@ -1346,7 +1346,7 @@ describe("generateReactQueryComponents", () => {
export const fetchAddPet = (variables: AddPetVariables, signal?: AbortSignal) => petstoreFetch<string, AddPetError, AddPetRequestBody, {}, {}, {}>({ url: "/pet", method: "get", ...variables, signal });
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, "mutationFn">) => {
const { fetcherOptions } = getPetstoreContext();
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
...options
@@ -1460,7 +1460,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as RequestBodies from "./petstoreRequestBodies";
@@ -1480,7 +1480,7 @@ describe("generateReactQueryComponents", () => {
export const fetchAddPet = (variables: AddPetVariables, signal?: AbortSignal) => petstoreFetch<string, AddPetError, RequestBodies.Dog, {}, {}, {}>({ url: "/pet", method: "post", ...variables, signal });
export const useAddPet = (options?: Omit<reactQuery.UseMutationOptions<string, AddPetError, AddPetVariables>, "mutationFn">) => {
const { fetcherOptions } = getPetstoreContext();
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, AddPetError, AddPetVariables>({
mutationFn: (variables: AddPetVariables) => fetchAddPet({ ...fetcherOptions, ...variables }),
...options
@@ -1573,7 +1573,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as RequestBodies from "./petstoreRequestBodies";
@@ -1592,7 +1592,7 @@ describe("generateReactQueryComponents", () => {
export const fetchUpdatePet = (variables: UpdatePetVariables, signal?: AbortSignal) => petstoreFetch<string, UpdatePetError, RequestBodies.UpdatePetRequestBody, {}, {}, UpdatePetPathParams>({ url: "/pet/{petId}", method: "put", ...variables, signal });
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, "mutationFn">) => {
const { fetcherOptions } = getPetstoreContext();
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
@@ -1685,7 +1685,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as RequestBodies from "./petstoreRequestBodies";
@@ -1704,7 +1704,7 @@ describe("generateReactQueryComponents", () => {
export const fetchUpdatePet = (variables: UpdatePetVariables, signal?: AbortSignal) => petstoreFetch<string, UpdatePetError, RequestBodies.UpdatePetRequestBody, {}, {}, UpdatePetPathParams>({ url: "/pet/{petId}", method: "put", ...variables, signal });
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, "mutationFn">) => {
const { fetcherOptions } = getPetstoreContext();
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
@@ -1797,7 +1797,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as RequestBodies from "./petstoreRequestBodies";
@@ -1816,7 +1816,7 @@ describe("generateReactQueryComponents", () => {
export const fetchUpdatePet = (variables: UpdatePetVariables, signal?: AbortSignal) => petstoreFetch<string, UpdatePetError, RequestBodies.UpdatePetRequestBody, {}, {}, UpdatePetPathParams>({ url: "/pet/{petId}", method: "put", ...variables, signal });
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, "mutationFn">) => {
const { fetcherOptions } = getPetstoreContext();
const { fetcherOptions } = usePetstoreContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
@@ -1909,7 +1909,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getContext, Context, queryKeyFn } from "./context";
import { useContext, Context, queryKeyFn } from "./context";
import type * as Fetcher from "./fetcher";
import { fetch } from "./fetcher";
import type * as RequestBodies from "./petstoreRequestBodies";
@@ -1928,7 +1928,7 @@ describe("generateReactQueryComponents", () => {
export const fetchUpdatePet = (variables: UpdatePetVariables, signal?: AbortSignal) => fetch<string, UpdatePetError, RequestBodies.UpdatePetRequestBody, {}, {}, UpdatePetPathParams>({ url: "/pet/{petId}", method: "put", ...variables, signal });
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, "mutationFn">) => {
const { fetcherOptions } = getContext();
const { fetcherOptions } = useContext();
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>({
mutationFn: (variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }),
...options
@@ -2005,7 +2005,7 @@ describe("generateReactQueryComponents", () => {
* @version 1.0.0
*/
import * as reactQuery from "@tanstack/react-query";
import { getPetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import { usePetstoreContext, PetstoreContext, queryKeyFn } from "./petstoreContext";
import type * as Fetcher from "./petstoreFetcher";
import { petstoreFetch } from "./petstoreFetcher";
import type * as Schemas from "./petstoreSchemas";
@@ -2047,7 +2047,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
export const useSuspenseListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useSuspenseQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
@@ -2056,7 +2056,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = getPetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, "queryKey" | "queryFn" | "initialData">) => { const { queryOptions } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>({
...listPetsQuery(variables),
...options,
...queryOptions
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ export const generateReactQueryComponents = async (

const fetcherFn = c.camel(`${filenamePrefix}-fetch`);
const contextTypeName = `${c.pascal(filenamePrefix)}Context`;
const contextHookName = `get${c.pascal(filenamePrefix)}Context`;
const contextHookName = `use${c.pascal(filenamePrefix)}Context`;
const nodes: ts.Node[] = [];
const keyManagerItems: ts.TypeLiteralNode[] = [];