@openapi-codegen/typescript
Advanced tools
Comparing version 8.0.2 to 8.1.0
@@ -18,3 +18,9 @@ import { ConfigBase, Context } from "./types"; | ||
injectedHeaders?: string[]; | ||
/** | ||
* Generate React Query components with `useSuspenseQuery` hook. | ||
* | ||
* @default false | ||
*/ | ||
generateSuspenseQueries?: boolean; | ||
}; | ||
export declare const generateReactQueryComponents: (context: Context, config: Config) => Promise<void>; |
@@ -40,2 +40,3 @@ "use strict"; | ||
const filename = formatFilename(filenamePrefix + "-components"); | ||
const { generateSuspenseQueries = false } = config; | ||
const fetcherFn = c.camel(`${filenamePrefix}-fetch`); | ||
@@ -94,2 +95,13 @@ const contextTypeName = `${c.pascal(filenamePrefix)}Context`; | ||
} | ||
const hookOptions = { | ||
operationFetcherFnName, | ||
operation, | ||
dataType, | ||
errorType, | ||
variablesType, | ||
contextHookName, | ||
name: `use${c.pascal(operationId)}`, | ||
operationId, | ||
url: route, | ||
}; | ||
nodes.push(...(0, createOperationFetcherFnNodes_1.createOperationFetcherFnNodes)({ | ||
@@ -108,23 +120,16 @@ dataType, | ||
name: operationFetcherFnName, | ||
}), ...(component === "useQuery" | ||
? createQueryHook({ | ||
operationFetcherFnName, | ||
operation, | ||
dataType, | ||
errorType, | ||
variablesType, | ||
contextHookName, | ||
name: `use${c.pascal(operationId)}`, | ||
operationId, | ||
url: route, | ||
}) | ||
: createMutationHook({ | ||
operationFetcherFnName, | ||
operation, | ||
dataType, | ||
errorType, | ||
variablesType, | ||
contextHookName, | ||
name: `use${c.pascal(operationId)}`, | ||
}))); | ||
})); | ||
if (component === "useQuery") { | ||
nodes.push(...createQueryHook(hookOptions)); | ||
if (generateSuspenseQueries) { | ||
nodes.push(...createQueryHook({ | ||
...hookOptions, | ||
name: `useSuspense${c.pascal(operationId)}`, | ||
useQueryIdentifier: "useSuspenseQuery", | ||
})); | ||
} | ||
} | ||
else { | ||
nodes.push(...createMutationHook(hookOptions)); | ||
} | ||
}); | ||
@@ -195,3 +200,3 @@ }); | ||
}; | ||
const createQueryHook = ({ operationFetcherFnName, contextHookName, dataType, errorType, variablesType, name, operationId, operation, url, }) => { | ||
const createQueryHook = ({ operationFetcherFnName, contextHookName, dataType, errorType, variablesType, name, operationId, operation, url, useQueryIdentifier = "useQuery", }) => { | ||
const nodes = []; | ||
@@ -215,3 +220,3 @@ if (operation.description) { | ||
], typescript_1.default.NodeFlags.Const)), | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("reactQuery"), typescript_1.factory.createIdentifier("useQuery")), [ | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("reactQuery"), typescript_1.factory.createIdentifier(useQueryIdentifier)), [ | ||
dataType, | ||
@@ -218,0 +223,0 @@ errorType, |
{ | ||
"name": "@openapi-codegen/typescript", | ||
"version": "8.0.2", | ||
"version": "8.1.0", | ||
"description": "OpenAPI Codegen typescript generators", | ||
@@ -44,3 +44,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "7b7904b60dd0f12c8c3c13271d1a30b6111f0c7b" | ||
"gitHead": "6c02ab3bdf93e3ae7a79d4ccc62321842152dc3c" | ||
} |
@@ -5,2 +5,8 @@ # OpenAPI Codegen typescript | ||
## Options | ||
### generateSuspenseQueries | ||
Generate `useSuspenseQuery` wrapper along side `useQuery`. | ||
## Generators | ||
@@ -7,0 +13,0 @@ |
Sorry, the diff of this file is not supported yet
240074
2933
263