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

Update infinite queries to use pageParams for continuation_token #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { useQuery, useInfiniteQuery, useMutation, UseQueryOptions, UseInfiniteQueryOptions, UseMutationOptions } from 'react-query';
import Axios from '../runtime';
import Axios, { PageParamType } from '../runtime';
import type { AxiosInstance } from 'axios';
{{#imports.0}}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -61,11 +61,11 @@ export const {{nickname}}QueryKey = (
{{#allParams.0}}
requestParametersQuery: {{operationIdCamelCase}}ForQuery,
{{/allParams.0}}
pageParam = -1,
pageParam: PageParamType = -1,
version = 1,
) => [
`/v${version}{{path}}`,
pageParam,
String(pageParam),
{{#allParams.0}}
...(requestParametersQuery ? [requestParametersQuery] : [])
{{/allParams.0}}
Expand All @@ -80,12 +80,15 @@ export const use{{vendorExtensions.nickname-capitalized}}InfiniteQuery = <Error
query?: UseInfiniteQueryOptions<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Data{{/returnType}}, Error>;
customAxiosInstance?: AxiosInstance;
},
pageParam = -1,
pageParam?: PageParamType,
version = 1,
) => {
const queryKey = {{nickname}}QueryKey({{#allParams.0}}params, {{/allParams.0}}pageParam, version);
const { query: queryOptions, customAxiosInstance } = options ?? {};

if (params.continuation_token == undefined) {
params.continuation_token = String(pageParam);
}
const query = useInfiniteQuery<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Data{{/returnType}}, Error>(
queryKey,
() => {{nickname}}AxiosRequest({{#allParams.0}}params, {{/allParams.0}}customAxiosInstance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Axios, { AxiosRequestConfig, AxiosInstance } from 'axios';
export const baseURL = '{{basePath}}';
export const AXIOS_INSTANCE = Axios.create({ baseURL, withCredentials: true });

export type PageParamType = string | number;

export const customInstance = <T>(config: AxiosRequestConfig, customAxiosInstance?: AxiosInstance): Promise<T> => {
const AXIOS_CUSTOM_INSTANCE = customAxiosInstance || AXIOS_INSTANCE;
const source = Axios.CancelToken.source();
Expand Down