Skip to content

Commit 44fa131

Browse files
committed
fix: allow providing custom query key to TanStack Query
1 parent 403d38a commit 44fa131

File tree

12 files changed

+339
-225
lines changed

12 files changed

+339
-225
lines changed

examples/openapi-ts-next/src/client/sdk.gen.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export type Options<
5252
* custom client.
5353
*/
5454
client?: Client;
55+
/**
56+
* You can pass arbitrary values through the `meta` object. This can be
57+
* used to access values that aren't defined as part of the SDK function.
58+
*/
59+
meta?: Record<string, unknown>;
5560
};
5661

5762
/**

packages/openapi-ts/src/generate/files.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,22 @@ export class TypeScriptFile {
202202
}): string {
203203
let filePath = '';
204204

205-
if (!id.startsWith('.')) {
205+
// relative file path
206+
if (id.startsWith('.')) {
207+
let configFileParts: Array<string> = [];
208+
// if providing a custom configuration file, relative paths must resolve
209+
// relative to the configuration file.
210+
if (context.config.configFile) {
211+
const cfgParts = context.config.configFile.split('/');
212+
configFileParts = cfgParts.slice(0, cfgParts.length - 1);
213+
}
214+
filePath = path.resolve(process.cwd(), ...configFileParts, id);
215+
} else {
206216
const file = context.file({ id });
207217
if (!file) {
208218
throw new Error(`File with id ${id} does not exist`);
209219
}
210-
211220
filePath = file._path;
212-
} else {
213-
filePath = path.resolve(process.cwd(), id);
214221
}
215222

216223
const thisPathParts = this._path.split(path.sep);

packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.d.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import type { Plugin } from '../../types';
2+
import type { TanStackQuery } from '../query-core/types';
23

34
export interface Config
4-
extends Plugin.Name<'@tanstack/angular-query-experimental'> {
5-
/**
6-
* Should the exports from the generated files be re-exported in the index
7-
* barrel file?
8-
*
9-
* @default false
10-
*/
11-
exportFromIndex?: boolean;
5+
extends Plugin.Name<'@tanstack/angular-query-experimental'>,
6+
TanStackQuery.Config {
127
/**
138
* Generate {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected.
149
*

packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ const createInfiniteParamsFunction = ({
3232
}) => {
3333
const file = context.file({ id: plugin.name })!;
3434

35+
if (plugin.runtimeConfigPath) {
36+
file.import({
37+
module: file.relativePathToFile({
38+
context,
39+
id: plugin.runtimeConfigPath,
40+
}),
41+
name: createInfiniteParamsFn,
42+
});
43+
return;
44+
}
45+
3546
const fn = compiler.constVariable({
3647
expression: compiler.arrowFunction({
3748
multiLine: true,
@@ -185,15 +196,15 @@ const createInfiniteParamsFunction = ({
185196
}),
186197
}),
187198
compiler.returnVariable({
188-
expression: ts.factory.createAsExpression(
189-
ts.factory.createAsExpression(
190-
compiler.identifier({ text: 'params' }),
191-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),
192-
),
193-
ts.factory.createTypeQueryNode(
199+
expression: compiler.asExpression({
200+
expression: compiler.asExpression({
201+
expression: compiler.identifier({ text: 'params' }),
202+
type: compiler.keywordTypeNode({ keyword: 'unknown' }),
203+
}),
204+
type: ts.factory.createTypeQueryNode(
194205
compiler.identifier({ text: 'page' }),
195206
),
196-
),
207+
}),
197208
}),
198209
],
199210
types: [

0 commit comments

Comments
 (0)