fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2115 from hey-api/fix/tanstack-query-infinite-params-copy

fix(tanstack-query): create a shallow copy of queryKey in createInfiniteParams function

authored by

Lubos and committed by
GitHub
8ae09612 fda3dd3e

+126 -47
+5
.changeset/perfect-garlics-return.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix(tanstack-query): create a shallow copy of queryKey in createInfiniteParams function
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts
··· 54 54 }; 55 55 56 56 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 57 - const params = queryKey[0]; 57 + const params = { 58 + ...queryKey[0] 59 + }; 58 60 if (page.body) { 59 61 params.body = { 60 62 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts
··· 337 337 }; 338 338 339 339 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 340 - const params = queryKey[0]; 340 + const params = { 341 + ...queryKey[0] 342 + }; 341 343 if (page.body) { 342 344 params.body = { 343 345 ...queryKey[0].body as any,
+3 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts
··· 336 336 }; 337 337 338 338 const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => { 339 - const params = queryKey[0]; 339 + const params = { 340 + ...queryKey[0] 341 + }; 340 342 if (page.body) { 341 343 params.body = { 342 344 ...queryKey[0].body as any,
+9 -9
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 44 44 // openapi: '3.1.0', 45 45 // paths: {}, 46 46 // }, 47 - path: path.resolve( 48 - __dirname, 49 - 'spec', 50 - '3.1.x', 51 - 'invalid', 52 - 'servers-entry.yaml', 53 - ), 54 - // path: path.resolve(__dirname, 'spec', '3.1.x', 'servers.yaml'), 47 + // path: path.resolve( 48 + // __dirname, 49 + // 'spec', 50 + // '3.1.x', 51 + // 'invalid', 52 + // 'servers-entry.yaml', 53 + // ), 54 + path: path.resolve(__dirname, 'spec', '3.1.x', 'full.json'), 55 55 // path: 'http://localhost:4000/', 56 56 // path: 'https://get.heyapi.dev/', 57 57 // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', ··· 136 136 }, 137 137 { 138 138 exportFromIndex: true, 139 - // name: '@tanstack/vue-query', 139 + name: '@tanstack/vue-query', 140 140 }, 141 141 { 142 142 // comments: false,
+10 -5
packages/openapi-ts/src/compiler/types.ts
··· 72 72 }: { 73 73 expression: string | ts.Expression; 74 74 isOptional?: boolean; 75 - name: string | ts.MemberName; 75 + name: string | number | ts.MemberName; 76 76 }): 77 77 | ts.PropertyAccessChain 78 78 | ts.PropertyAccessExpression ··· 82 82 ? createIdentifier({ text: expression }) 83 83 : expression; 84 84 85 - if (isOptional) { 85 + if (isOptional && typeof name !== 'number') { 86 86 return createPropertyAccessChain({ 87 87 expression: nodeExpression, 88 88 name, ··· 100 100 const nodeName = createIdentifier({ text: name }); 101 101 return ts.factory.createElementAccessExpression(nodeExpression, nodeName); 102 102 } 103 + 104 + const nodeName = createIdentifier({ text: name }); 105 + return ts.factory.createPropertyAccessExpression(nodeExpression, nodeName); 103 106 } 104 107 105 - const nodeName = 106 - typeof name === 'string' ? createIdentifier({ text: name }) : name; 108 + if (typeof name === 'number') { 109 + const nodeName = ts.factory.createNumericLiteral(name); 110 + return ts.factory.createElementAccessExpression(nodeExpression, nodeName); 111 + } 107 112 108 - return ts.factory.createPropertyAccessExpression(nodeExpression, nodeName); 113 + return ts.factory.createPropertyAccessExpression(nodeExpression, name); 109 114 }; 110 115 111 116 export const createNull = (): ts.NullLiteral => ts.factory.createNull();
+9 -2
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 50 50 ], 51 51 statements: [ 52 52 compiler.constVariable({ 53 - expression: compiler.identifier({ 54 - text: 'queryKey[0]', 53 + expression: compiler.objectExpression({ 54 + obj: [ 55 + { 56 + spread: compiler.propertyAccessExpression({ 57 + expression: 'queryKey', 58 + name: 0, 59 + }), 60 + }, 61 + ], 55 62 }), 56 63 name: 'params', 57 64 }),