|
6 | 6 |
|
7 | 7 | ## Features |
8 | 8 |
|
9 | | -- Generates custom react hooks that use React Query's `useQuery`, `useSuspenseQuery` and `useMutation` hooks |
| 9 | +- Generates custom react hooks that use React Query's `useQuery`, `useSuspenseQuery`, `useMutation` and `useInfiniteQuery` hooks |
10 | 10 | - Generates query keys and functions for query caching |
11 | 11 | - Generates pure TypeScript clients generated by [@hey-api/openapi-ts](https://github.com/hey-api/openapi-ts) |
12 | 12 |
|
@@ -45,18 +45,20 @@ Options: |
45 | 45 | -V, --version output the version number |
46 | 46 | -i, --input <value> OpenAPI specification, can be a path, url or string content (required) |
47 | 47 | -o, --output <value> Output directory (default: "openapi") |
48 | | - -c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch") |
| 48 | + -c, --client <value> HTTP client to generate (choices: "angular", "axios", "fetch", "node", "xhr", default: "fetch") |
49 | 49 | --request <value> Path to custom request file |
50 | | - --format <value> Process output folder with formatter? ['biome', 'prettier'] |
51 | | - --lint <value> Process output folder with linter? ['eslint', 'biome'] |
| 50 | + --format <value> Process output folder with formatter? (choices: "biome", "prettier") |
| 51 | + --lint <value> Process output folder with linter? (choices: "biome", "eslint") |
52 | 52 | --operationId Use operation ID to generate operation names? |
53 | | - --serviceResponse <value> Define shape of returned value from service calls ['body', 'response'] (default: "body") |
| 53 | + --serviceResponse <value> Define shape of returned value from service calls (choices: "body", "response", default: "body") |
54 | 54 | --base <value> Manually set base in OpenAPI config instead of inferring from server value |
55 | | - --enums <value> Generate JavaScript objects from enum definitions? ['javascript', 'typescript'] |
| 55 | + --enums <value> Generate JavaScript objects from enum definitions? (choices: "javascript", "typescript") |
56 | 56 | --useDateType Use Date type instead of string for date types for models, this will not convert the data to a Date object |
57 | | - --debug Enable debug mode |
58 | | - --noSchemas Disable generating schemas for request and response objects |
59 | | - --schemaTypes <value> Define the type of schema generation ['form', 'json'] (default: "json") |
| 57 | + --debug Run in debug mode? |
| 58 | + --noSchemas Disable generating JSON schemas |
| 59 | + --schemaType <value> Type of JSON schema [Default: 'json'] (choices: "form", "json") |
| 60 | + --pageParam <value> Name of the query parameter used for pagination (default: "page") |
| 61 | + --nextPageParam <value> Name of the response parameter used for next page (default: "nextPage") |
60 | 62 | -h, --help display help for command |
61 | 63 | ``` |
62 | 64 |
|
@@ -234,6 +236,72 @@ function App() { |
234 | 236 | export default App; |
235 | 237 | ``` |
236 | 238 |
|
| 239 | +##### Using Infinite Query hooks |
| 240 | + |
| 241 | +This feature will generate a function in infiniteQueries.ts when the name specified by the `pageParam` option exists in the query parameters and the name specified by the `nextPageParam` option exists in the response. |
| 242 | + |
| 243 | +Example Schema: |
| 244 | + |
| 245 | +```yml |
| 246 | +paths: |
| 247 | + /paginated-pets: |
| 248 | + get: |
| 249 | + description: | |
| 250 | + Returns paginated pets from the system that the user has access to |
| 251 | + operationId: findPaginatedPets |
| 252 | + parameters: |
| 253 | + - name: page |
| 254 | + in: query |
| 255 | + description: page number |
| 256 | + required: false |
| 257 | + schema: |
| 258 | + type: integer |
| 259 | + format: int32 |
| 260 | + - name: tags |
| 261 | + in: query |
| 262 | + description: tags to filter by |
| 263 | + required: false |
| 264 | + style: form |
| 265 | + schema: |
| 266 | + type: array |
| 267 | + items: |
| 268 | + type: string |
| 269 | + - name: limit |
| 270 | + in: query |
| 271 | + description: maximum number of results to return |
| 272 | + required: false |
| 273 | + schema: |
| 274 | + type: integer |
| 275 | + format: int32 |
| 276 | + responses: |
| 277 | + '200': |
| 278 | + description: pet response |
| 279 | + content: |
| 280 | + application/json: |
| 281 | + schema: |
| 282 | + type: object |
| 283 | + properties: |
| 284 | + pets: |
| 285 | + type: array |
| 286 | + items: |
| 287 | + $ref: '#/components/schemas/Pet' |
| 288 | + nextPage: |
| 289 | + type: integer |
| 290 | + format: int32 |
| 291 | + minimum: 1 |
| 292 | +``` |
| 293 | +
|
| 294 | +Usage of Generated Hooks: |
| 295 | +
|
| 296 | +```ts |
| 297 | +import { useDefaultServiceFindPaginatedPetsInfinite } from "@/openapi/queries/infiniteQueries"; |
| 298 | + |
| 299 | +const { data, fetchNextPage } = useDefaultServiceFindPaginatedPetsInfinite({ |
| 300 | + limit: 10, |
| 301 | + tags: [], |
| 302 | +}); |
| 303 | +``` |
| 304 | + |
237 | 305 | ##### Runtime Configuration |
238 | 306 |
|
239 | 307 | You can modify the default values used by the generated service calls by modifying the OpenAPI configuration singleton object. |
|
0 commit comments