@@ -220,6 +220,7 @@ This is a monorepo containing multiple packages:
220220- ** ` @devup-api/utils ` ** - Utility functions for OpenAPI processing
221221- ** ` @devup-api/generator ` ** - TypeScript interface generator from OpenAPI schemas
222222- ** ` @devup-api/fetch ` ** - Type-safe API client
223+ - ** ` @devup-api/react-query ` ** - TanStack React Query integration
223224- ** ` @devup-api/vite-plugin ` ** - Vite plugin
224225- ** ` @devup-api/next-plugin ` ** - Next.js plugin
225226- ** ` @devup-api/webpack-plugin ` ** - Webpack plugin
@@ -276,6 +277,151 @@ if (result.data) {
276277}
277278```
278279
280+ ### ** Using DevupObject for Type References**
281+
282+ ` DevupObject ` allows you to reference generated schema types directly, which is useful for typing variables, function parameters, or component props.
283+
284+ ``` ts
285+ import { createApi , type DevupObject } from ' @devup-api/fetch'
286+
287+ // Access response types from the default OpenAPI schema
288+ type User = DevupObject [' User' ]
289+ type Product = DevupObject [' Product' ]
290+
291+ // Use in your code
292+ const user: User = {
293+ id: ' 123' ,
294+ name: ' John Doe' ,
295+ 296+ }
297+
298+ // For request/error types, specify the type category
299+ type CreateUserRequest = DevupObject <' request' >[' CreateUserBody' ]
300+ type ApiError = DevupObject <' error' >[' ErrorResponse' ]
301+ ` ` `
302+
303+ ---
304+
305+ ## 🌐 Multiple API Servers
306+
307+ devup-api supports multiple OpenAPI schemas for working with different API servers.
308+
309+ ### **Configuration**
310+
311+ Place multiple OpenAPI files in your project (e.g., ` openapi .json ` , ` openapi2 .json ` ) and the plugin will generate types for each.
312+
313+ ### **Usage**
314+
315+ ` ` ` ts
316+ import { createApi , type DevupObject } from ' @devup-api/fetch'
317+
318+ // Default server (uses openapi.json)
319+ const api = createApi ({
320+ baseUrl: ' https://api.example.com' ,
321+ })
322+
323+ // Second server (uses openapi2.json)
324+ const api2 = createApi ({
325+ baseUrl: ' https://api.another-service.com' ,
326+ serverName: ' openapi2.json' ,
327+ })
328+
329+ // Make requests to different servers
330+ const users = await api .get (' getUsers' , {})
331+ const products = await api2 .get (' getProducts' , {})
332+
333+ // Access types from different schemas
334+ type User = DevupObject [' User' ] // From openapi.json
335+ type Product = DevupObject <' response' , ' openapi2.json' >[' Product' ] // From openapi2.json
336+ ` ` `
337+
338+ ---
339+
340+ ## 🔄 React Query Integration
341+
342+ devup-api provides first-class support for TanStack React Query through the ` @devup -api /react -query ` package.
343+
344+ ### **Installation**
345+
346+ ` ` ` bash
347+ npm install @devup -api /react -query @tanstack /react -query
348+ ` ` `
349+
350+ ### **Setup**
351+
352+ ` ` ` ts
353+ import { createApi } from ' @devup-api/fetch'
354+ import { createQueryClient } from ' @devup-api/react-query'
355+
356+ const api = createApi (' https://api.example.com' )
357+ const queryClient = createQueryClient (api )
358+ ```
359+
360+ ### ** useQuery**
361+
362+ ``` ts
363+ function UserProfile({ userId }: { userId: string }) {
364+ const { data, isLoading, error } = queryClient .useQuery (
365+ ' get' ,
366+ ' /users/{id}' ,
367+ { params: { id: userId } }
368+ )
369+
370+ if (isLoading ) return <div >Loading ... < / div >
371+ if (error ) return <div >Error : {error.message }< / div >
372+ return <div >{data.name }< / div >
373+ }
374+ ```
375+
376+ ### ** useMutation**
377+
378+ ``` ts
379+ function CreateUser() {
380+ const mutation = queryClient .useMutation (' post' , ' createUser' )
381+
382+ return (
383+ < button onClick = {() => mutation.mutate({
384+ body : {
name :
' John' ,
email :
' [email protected] ' }
385+ })}>
386+ Create User
387+ < / button >
388+ )
389+ }
390+ ```
391+
392+ ### ** useSuspenseQuery**
393+
394+ ``` ts
395+ function UserList() {
396+ const { data } = queryClient .useSuspenseQuery (' get' , ' getUsers' , {})
397+ return <ul >{data.map(user => <li key ={user .id}>{user.name }< / li > )}< / ul >
398+ }
399+ ```
400+
401+ ### ** useInfiniteQuery**
402+
403+ ``` ts
404+ function InfiniteUserList() {
405+ const { data, fetchNextPage, hasNextPage } = queryClient .useInfiniteQuery (
406+ ' get' ,
407+ ' getUsers' ,
408+ {
409+ initialPageParam: 1 ,
410+ getNextPageParam : (lastPage ) => lastPage .nextPage ,
411+ }
412+ )
413+
414+ return (
415+ <>
416+ {data ?.pages .map (page = >
417+ page .users .map (user = > <div key ={user .id}>{user.name }< / div > )
418+ )}
419+ {hasNextPage && <button onClick = {() => fetchNextPage()}> Load More < / button > }
420+ < / >
421+ )
422+ }
423+ ```
424+
279425---
280426
281427## ⚙️ Configuration Options
0 commit comments