diff --git a/README.md b/README.md index 13ac2e8..b014cb1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Features -- Generates custom react hooks that use React Query's `useQuery`, `useSuspenseQuery` and `useMutation` hooks +- Generates custom react hooks that use React Query's `useQuery`, `useSuspenseQuery`, `useMutation` and `useInfiniteQuery` hooks - Generates query keys and functions for query caching - Generates pure TypeScript clients generated by [@hey-api/openapi-ts](https://github.com/hey-api/openapi-ts) @@ -45,18 +45,20 @@ Options: -V, --version output the version number -i, --input OpenAPI specification, can be a path, url or string content (required) -o, --output Output directory (default: "openapi") - -c, --client HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch") + -c, --client HTTP client to generate (choices: "angular", "axios", "fetch", "node", "xhr", default: "fetch") --request Path to custom request file - --format Process output folder with formatter? ['biome', 'prettier'] - --lint Process output folder with linter? ['eslint', 'biome'] + --format Process output folder with formatter? (choices: "biome", "prettier") + --lint Process output folder with linter? (choices: "biome", "eslint") --operationId Use operation ID to generate operation names? - --serviceResponse Define shape of returned value from service calls ['body', 'response'] (default: "body") + --serviceResponse Define shape of returned value from service calls (choices: "body", "response", default: "body") --base Manually set base in OpenAPI config instead of inferring from server value - --enums Generate JavaScript objects from enum definitions? ['javascript', 'typescript'] + --enums Generate JavaScript objects from enum definitions? (choices: "javascript", "typescript") --useDateType Use Date type instead of string for date types for models, this will not convert the data to a Date object - --debug Enable debug mode - --noSchemas Disable generating schemas for request and response objects - --schemaTypes Define the type of schema generation ['form', 'json'] (default: "json") + --debug Run in debug mode? + --noSchemas Disable generating JSON schemas + --schemaType Type of JSON schema [Default: 'json'] (choices: "form", "json") + --pageParam Name of the query parameter used for pagination (default: "page") + --nextPageParam Name of the response parameter used for next page (default: "nextPage") -h, --help display help for command ``` @@ -234,6 +236,72 @@ function App() { export default App; ``` +##### Using Infinite Query hooks + +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. + +Example Schema: + +```yml +paths: + /paginated-pets: + get: + description: | + Returns paginated pets from the system that the user has access to + operationId: findPaginatedPets + parameters: + - name: page + in: query + description: page number + required: false + schema: + type: integer + format: int32 + - name: tags + in: query + description: tags to filter by + required: false + style: form + schema: + type: array + items: + type: string + - name: limit + in: query + description: maximum number of results to return + required: false + schema: + type: integer + format: int32 + responses: + '200': + description: pet response + content: + application/json: + schema: + type: object + properties: + pets: + type: array + items: + $ref: '#/components/schemas/Pet' + nextPage: + type: integer + format: int32 + minimum: 1 +``` + +Usage of Generated Hooks: + +```ts +import { useDefaultServiceFindPaginatedPetsInfinite } from "@/openapi/queries/infiniteQueries"; + +const { data, fetchNextPage } = useDefaultServiceFindPaginatedPetsInfinite({ + limit: 10, + tags: [], +}); +``` + ##### Runtime Configuration You can modify the default values used by the generated service calls by modifying the OpenAPI configuration singleton object.