Skip to content

Commit

Permalink
fix: edit format
Browse files Browse the repository at this point in the history
  • Loading branch information
jungwoo3490 committed Aug 27, 2024
1 parent 054202f commit ccf4c8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions packages/openapi-react-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
useInfiniteQuery,
} from "@tanstack/react-query";
import type { ClientMethod, FetchResponse, MaybeOptionalInit, Client as FetchClient } from "openapi-fetch";
import type { HttpMethod, MediaType, PathsWithMethod, RequiredKeysOf, ResponseObjectMap } from "openapi-typescript-helpers";
import type {
HttpMethod,
MediaType,
PathsWithMethod,
RequiredKeysOf,
ResponseObjectMap,
} from "openapi-typescript-helpers";

export type UseQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
Method extends HttpMethod,
Expand Down Expand Up @@ -146,9 +152,9 @@ export default function createClient<Paths extends {}, Media extends MediaType =
queryFn: async ({ pageParam = 0 }) => {
const mth = method.toUpperCase() as keyof typeof client;
const fn = client[mth] as ClientMethod<Paths, typeof method, Media>;

const params = pageParam === 0 ? init : { ...init, page: pageParam };

const { data, error } = await fn(path, params as any); // TODO: find a way to avoid as any
if (error || !data) {
throw error;
Expand Down
6 changes: 3 additions & 3 deletions packages/openapi-react-query/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ describe("client", () => {

const { result } = renderHook(
() => client.useInfiniteQuery("get", "/paginated-data", { params: { query: { limit: 3 } } }),
{ wrapper }
{ wrapper },
);

await waitFor(() => expect(result.current.isSuccess).toBe(true));
Expand All @@ -489,7 +489,7 @@ describe("client", () => {

expect((result.current.data as any).pages).toHaveLength(2);
expect((result.current.data as any).pages[1]).toEqual({ items: [4, 5, 6], nextPage: 2 });
});
});

it("should handle errors correctly", async () => {
const fetchClient = createFetchClient<paths>({ baseUrl });
Expand All @@ -505,7 +505,7 @@ describe("client", () => {

const { result } = renderHook(
() => client.useInfiniteQuery("get", "/paginated-data", { params: { query: { limit: 3 } } }),
{ wrapper }
{ wrapper },
);

await waitFor(() => expect(result.current.isError).toBe(true));
Expand Down

0 comments on commit ccf4c8a

Please sign in to comment.