Skip to content

Commit 89e0de8

Browse files
authored
fix(query): resolve global query mutators against output workspace (#3604)
1 parent 25a0a0d commit 89e0de8

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

packages/orval/src/utils/options.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,48 @@ describe('normalizeOptions', () => {
743743
}
744744
});
745745

746+
it('resolves global query mutators relative to the output workspace', async () => {
747+
const workspace = await createTempWorkspace();
748+
749+
try {
750+
const outputWorkspace = path.join(workspace, 'generated');
751+
const normalized = await normalizeOptions(
752+
{
753+
input: {
754+
target: {
755+
openapi: '3.1.0',
756+
info: { title: 'Test', version: '1.0.0' },
757+
paths: {},
758+
},
759+
},
760+
output: {
761+
target: './api.ts',
762+
workspace: './generated',
763+
client: 'react-query',
764+
override: {
765+
query: {
766+
queryKey: './queryKey.ts',
767+
queryOptions: './queryOptions.ts',
768+
mutationOptions: './mutationOptions.ts',
769+
},
770+
},
771+
},
772+
},
773+
workspace,
774+
);
775+
776+
expect(normalized.output.override.query).toMatchObject({
777+
queryKey: { path: path.join(outputWorkspace, 'queryKey.ts') },
778+
queryOptions: { path: path.join(outputWorkspace, 'queryOptions.ts') },
779+
mutationOptions: {
780+
path: path.join(outputWorkspace, 'mutationOptions.ts'),
781+
},
782+
});
783+
} finally {
784+
await rm(workspace, { recursive: true, force: true });
785+
}
786+
});
787+
746788
it('normalizes effect options without falling back to zod', async () => {
747789
const workspace = await createTempWorkspace();
748790

packages/orval/src/utils/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export async function normalizeOptions(
339339
shouldExportQueryKey: true,
340340
shouldFilterQueryKey: false,
341341
shouldSplitQueryKey: false,
342-
...normalizeQueryOptions(outputOptions.override?.query, workspace),
342+
...normalizeQueryOptions(outputOptions.override?.query, outputWorkspace),
343343
};
344344

345345
const normalizedOptions: NormalizedOptions = {

0 commit comments

Comments
 (0)