Node.js library that generates React Query (also called TanStack Query) hooks based on an OpenAPI specification file.
Installations
npm install @davstack/openapi-react-query-codegen
Developer Guide
Typescript
No
Module System
N/A
Node Version
18.16.0
NPM Version
9.6.6
Score
63.9
Supply Chain
97.5
Quality
75.3
Maintenance
100
Vulnerability
99.3
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (95.61%)
JavaScript (4.39%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
DawidWraga
Download Statistics
Total Downloads
2,398
Last Day
1
Last Week
2
Last Month
32
Last Year
518
GitHub Statistics
70 Commits
1 Branches
1 Contributors
Updated on Jul 08, 2023
Package Meta Information
Latest Version
0.8.5
Package Id
@davstack/openapi-react-query-codegen@0.8.5
Unpacked Size
62.02 kB
Size
8.31 kB
File Count
27
NPM Version
9.6.6
Node Version
18.16.0
Published on
Jul 24, 2023
Total Downloads
Cumulative downloads
Total Downloads
2,398
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
-52.9%
32
Compared to previous month
Last Year
-72.4%
518
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
4
Dev Dependencies
5
OpenAPI React Query Codegen
Node.js library that generates React Query (also called TanStack Query) hooks based on an OpenAPI specification file.
Features
- Supports generation of custom react hooks that use React Query's
useQuery
anduseMutation
hooks - Supports generation of query keys for query caching
- Supports the option to use pure TypeScript clients generated by OpenAPI Typescript Codegen
Install
$ npm i -D @davstack/openapi-react-query-codegen
Usage
$ openapi-rq --help
Usage: openapi-rq [options]
Generate React Query code based on OpenAPI
Options:
-V, --version output the version number
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
-o, --output <value> Output directory (default: "openapi")
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
--useUnionTypes Use union types (default: false)
--exportSchemas <value> Write schemas to disk (default: false)
--indent <value> Indentation options [4, 2, tabs] (default: "4")
--postfixServices <value> Service name postfix (default: "Service")
--postfixModels <value> Modal name postfix
--request <value> Path to custom request file
-h, --help display help for command
Example Usage
Command
$ openapi-rq -i ./petstore.yaml
Output directory structure
- openapi
- queries
- index.ts <- custom react hooks
- requests <- output code generated by OpenAPI Typescript Codegen
In your app
1// App.tsx 2import { 3 usePetServiceFindPetsByStatus, 4} from "../openapi/queries"; 5function App() { 6 const { data } = usePetServiceFindPetsByStatus({ status: ["available"] }); 7 8 return ( 9 <div className="App"> 10 <h1>Pet List</h1> 11 <ul> 12 {data?.map((pet) => ( 13 <li key={pet.id}>{pet.name}</li> 14 ))} 15 </ul> 16 </div> 17 ); 18} 19 20export default App;
You can also use pure TS clients.
1import { useQuery } from "@tanstack/react-query"; 2import { PetService } from '../openapi/requests/services/PetService'; 3import { 4 usePetServiceFindPetsByStatusKey, 5} from "../openapi/queries"; 6 7function App() { 8 // You can still use the auto-generated query key 9 const { data } = useQuery([usePetServiceFindPetsByStatusKey], () => { 10 // Do something here 11 12 return PetService.findPetsByStatus(['available']); 13 }); 14 15 return ( 16 <div className="App"> 17 {/* .... */} 18 </div> 19 ); 20} 21 22export default App;
License
MIT

No vulnerabilities found.

No security vulnerabilities found.