响应查询插件
插件用于 oats cli,用于生成反应查询钩. 这将生成钩子
使用 react-query。 。 。 .
安装
利用国家预防机制:
npm i -D @harnessio/oats-cli @harnessio/oats-plugin-react-query
使用 Yarn :
yarn add -D @harnessio/oats-cli @harnessio/oats-plugin-react-query
使用量
// oats.config.ts
import { defineConfig } from '@harnessio/oats-cli/config';
import reactQueryPlugin from '@harnessio/oats-plugin-react-query';
export default defineConfig({
plugins: [
reactQueryPlugin({
/**
* Path poiniting to the file where the custom fetcher resides.
* This path will be used as is, while generating the hooks.
*
* This path must be a relative path which can be resolved with respect
* to a file within the hooks folder.
*/
customFetcher: '../realtive/path/to/custom/fetcher',
/**
* An allow-list, for filtering out operation IDs which are to be generated.
*
* When defined, hooks will be generated only for the operation IDs
* defined in this list.
*
* This field is optional.
*/
allowedOperationIds: [],
/**
* Override options per operation.
* The key must the operation Id from the spec.
* This field is optional.
*/
overrides: {
operationId: {
/**
* By default, any operation expect "GET", will generate a mutation
* hook using `useMutation`. This option can be used to overide this
* behaviour for a given operation ID.
*
* When set to `true`, no matter what the verb, query hook will be
* generated using `useQuery`.
*/
useQuery: true,
},
},
}),
],
});
自定义获取器
此插件会为您生成一个基本的获取器, 但这在 现实世界 您可以提供自己的获取器功能,处理您的使用大小写 .
您可以使用 customFetcher 相会. 应该是绳子
指向带有自定义获取器的文件 。 文件必须导出一个函数
名称 fetcher 和接口 FetcherOptions 签字日期:
export interface FetcherOptions<TQueryParams = never, TBody = never>
extends Omit<RequestInit, 'body'> {
url: string;
queryParams?: TQueryParams extends never ? undefined : TQueryParams;
body?: TBody extends never ? undefined : TBody;
}
export function fetcher<TResponse = unknown, TQueryParams = never, TBody = never>(
options: FetcherOptions<TQueryParams, TBody>,
): Promise<TResponse> {
// your code here
}
您可以添加额外的属性到 FetcherOptions 根据你的要求,
因为这些额外的属性将从钩子传递到取取器.
你可以看看那个 在此生成的默认获取器