@openapi-qraft/react 2.10.2 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/dist/cjs/callbacks/getMutationCache.cjs +26 -0
- package/dist/cjs/callbacks/getMutationCache.cjs.map +1 -0
- package/dist/cjs/callbacks/index.cjs +2 -0
- package/dist/cjs/callbacks/index.cjs.map +1 -1
- package/dist/cjs/lib/composeMutationFilters.cjs +4 -2
- package/dist/cjs/lib/composeMutationFilters.cjs.map +1 -1
- package/dist/cjs/lib/composeMutationKey.cjs +0 -1
- package/dist/cjs/lib/composeMutationKey.cjs.map +1 -1
- package/dist/esm/callbacks/getMutationCache.js +24 -0
- package/dist/esm/callbacks/getMutationCache.js.map +1 -0
- package/dist/esm/callbacks/index.js +1 -0
- package/dist/esm/callbacks/index.js.map +1 -1
- package/dist/esm/lib/composeMutationFilters.js +4 -2
- package/dist/esm/lib/composeMutationFilters.js.map +1 -1
- package/dist/esm/lib/composeMutationKey.js +1 -1
- package/dist/esm/lib/composeMutationKey.js.map +1 -1
- package/dist/types/callbacks/getMutationCache.d.ts +4 -0
- package/dist/types/callbacks/getMutationCache.d.ts.map +1 -0
- package/dist/types/callbacks/index.d.ts +1 -0
- package/dist/types/callbacks/index.d.ts.map +1 -1
- package/dist/types/lib/composeMutationFilters.d.ts +1 -0
- package/dist/types/lib/composeMutationFilters.d.ts.map +1 -1
- package/dist/types/lib/composeMutationKey.d.ts +0 -1
- package/dist/types/lib/composeMutationKey.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/callbacks/getMutationCache.ts +31 -0
- package/src/callbacks/index.ts +1 -0
- package/src/lib/composeMutationFilters.ts +3 -1
- package/src/lib/composeMutationKey.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @openapi-qraft/react
|
|
2
2
|
|
|
3
|
+
## 2.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cdc4bf3: Resolve unmet peerDependencies.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @openapi-qraft/tanstack-query-react-types@2.12.0
|
|
12
|
+
|
|
13
|
+
## 2.11.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 56f4ae9: Added `getMutationCache()` method to query client operations.
|
|
18
|
+
- 7f63c73: getMutationCache() auto-sets `exact: false` for base filters
|
|
19
|
+
|
|
20
|
+
When calling `getMutationCache().find()` or `getMutationCache().findAll()` without providing `parameters` or
|
|
21
|
+
`mutationKey` filters, the `exact` option is now automatically set to `false`.
|
|
22
|
+
|
|
23
|
+
**Why this change?**
|
|
24
|
+
|
|
25
|
+
TanStack Query sets `exact: true` by default for mutation filters. Without this automatic override,
|
|
26
|
+
no mutations would match when using only predicate functions or no filters at all,
|
|
27
|
+
since the base mutation key wouldn't match exactly against specific mutation instances.
|
|
28
|
+
|
|
29
|
+
**Example:**
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// Returns all mutations for the endpoint due to auto-set exact: false
|
|
33
|
+
const mutations = qraft.entities.postEntitiesIdDocuments
|
|
34
|
+
.getMutationCache()
|
|
35
|
+
.findAll();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This ensures that predicate-based filtering and endpoint-wide mutation searches work as expected.
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [56f4ae9]
|
|
43
|
+
- @openapi-qraft/tanstack-query-react-types@2.11.0
|
|
44
|
+
|
|
3
45
|
## 2.10.2
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var composeMutationFilters = require('../lib/composeMutationFilters.cjs');
|
|
4
|
+
|
|
5
|
+
function getMutationCache(qraftOptions, schema) {
|
|
6
|
+
const mutationCache = qraftOptions.queryClient.getMutationCache();
|
|
7
|
+
return wrapMutationCacheMethods(schema, mutationCache);
|
|
8
|
+
}
|
|
9
|
+
function wrapMutationCacheMethods(schema, original) {
|
|
10
|
+
return new Proxy(original, {
|
|
11
|
+
get (target, prop, receiver) {
|
|
12
|
+
if (prop === 'find' || prop === 'findAll') {
|
|
13
|
+
return function(...args) {
|
|
14
|
+
return Reflect.apply(target[prop], target, [
|
|
15
|
+
composeMutationFilters.composeMutationFilters(schema, args[0]),
|
|
16
|
+
...args.slice(1, args.length)
|
|
17
|
+
]);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return Reflect.get(target, prop, receiver);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.getMutationCache = getMutationCache;
|
|
26
|
+
//# sourceMappingURL=getMutationCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMutationCache.cjs","sources":["../../../src/callbacks/getMutationCache.ts"],"sourcesContent":["import type { OperationSchema } from '@openapi-qraft/tanstack-query-react-types';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport function getMutationCache(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema\n) {\n const mutationCache = qraftOptions.queryClient.getMutationCache();\n\n return wrapMutationCacheMethods(schema, mutationCache);\n}\n\nfunction wrapMutationCacheMethods<\n T extends Record<'find' | 'findAll', (...args: any[]) => any>,\n>(schema: OperationSchema, original: T): T {\n return new Proxy(original, {\n get(target, prop, receiver) {\n if (prop === 'find' || prop === 'findAll') {\n return function (...args: any[]) {\n return Reflect.apply(target[prop], target, [\n composeMutationFilters(schema, args[0] as never),\n ...args.slice(1, args.length),\n ]);\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n"],"names":["getMutationCache","qraftOptions","schema","mutationCache","queryClient","wrapMutationCacheMethods","original","Proxy","get","target","prop","receiver","args","Reflect","apply","composeMutationFilters","slice","length"],"mappings":";;;;AAIO,SAASA,gBAAAA,CACdC,YAAyC,EACzCC,MAAuB,EAAA;AAEvB,IAAA,MAAMC,aAAgBF,GAAAA,YAAAA,CAAaG,WAAW,CAACJ,gBAAgB,EAAA,CAAA;AAE/D,IAAA,OAAOK,yBAAyBH,MAAQC,EAAAA,aAAAA,CAAAA,CAAAA;AAC1C,CAAA;AAEA,SAASE,wBAAAA,CAEPH,MAAuB,EAAEI,QAAW,EAAA;IACpC,OAAO,IAAIC,MAAMD,QAAU,EAAA;AACzBE,QAAAA,GAAAA,CAAAA,CAAIC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAA;YACxB,IAAID,IAAAA,KAAS,MAAUA,IAAAA,IAAAA,KAAS,SAAW,EAAA;gBACzC,OAAO,SAAU,GAAGE,IAAW,EAAA;AAC7B,oBAAA,OAAOC,QAAQC,KAAK,CAACL,MAAM,CAACC,IAAAA,CAAK,EAAED,MAAQ,EAAA;wBACzCM,6CAAuBb,CAAAA,MAAAA,EAAQU,IAAI,CAAC,CAAE,CAAA,CAAA;AACnCA,wBAAAA,GAAAA,IAAAA,CAAKI,KAAK,CAAC,CAAGJ,EAAAA,IAAAA,CAAKK,MAAM,CAAA;AAC7B,qBAAA,CAAA,CAAA;AACH,iBAAA,CAAA;AACF,aAAA;AAEA,YAAA,OAAOJ,OAAQL,CAAAA,GAAG,CAACC,MAAAA,EAAQC,IAAMC,EAAAA,QAAAA,CAAAA,CAAAA;AACnC,SAAA;AACF,KAAA,CAAA,CAAA;AACF;;;;"}
|
|
@@ -25,6 +25,7 @@ var removeQueries = require('./removeQueries.cjs');
|
|
|
25
25
|
var refetchQueries = require('./refetchQueries.cjs');
|
|
26
26
|
var isFetching = require('./isFetching.cjs');
|
|
27
27
|
var isMutating = require('./isMutating.cjs');
|
|
28
|
+
var getMutationCache = require('./getMutationCache.cjs');
|
|
28
29
|
var useIsFetching = require('./useIsFetching.cjs');
|
|
29
30
|
var fetchQuery = require('./fetchQuery.cjs');
|
|
30
31
|
var prefetchQuery = require('./prefetchQuery.cjs');
|
|
@@ -63,6 +64,7 @@ exports.removeQueries = removeQueries.removeQueries;
|
|
|
63
64
|
exports.refetchQueries = refetchQueries.refetchQueries;
|
|
64
65
|
exports.isFetching = isFetching.isFetching;
|
|
65
66
|
exports.isMutating = isMutating.isMutating;
|
|
67
|
+
exports.getMutationCache = getMutationCache.getMutationCache;
|
|
66
68
|
exports.useIsFetching = useIsFetching.useIsFetching;
|
|
67
69
|
exports.fetchQuery = fetchQuery.fetchQuery;
|
|
68
70
|
exports.prefetchQuery = prefetchQuery.prefetchQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -10,6 +10,7 @@ var composeMutationKey = require('./composeMutationKey.cjs');
|
|
|
10
10
|
*/ function composeMutationFilters(schema, filters) {
|
|
11
11
|
if (!filters) {
|
|
12
12
|
return {
|
|
13
|
+
exact: false,
|
|
13
14
|
mutationKey: composeMutationKey.composeMutationKey(schema, undefined)
|
|
14
15
|
};
|
|
15
16
|
}
|
|
@@ -27,8 +28,9 @@ var composeMutationKey = require('./composeMutationKey.cjs');
|
|
|
27
28
|
return filtersWithoutParameters;
|
|
28
29
|
}
|
|
29
30
|
return {
|
|
30
|
-
|
|
31
|
-
mutationKey: composeMutationKey.composeMutationKey(schema, undefined)
|
|
31
|
+
exact: false,
|
|
32
|
+
mutationKey: composeMutationKey.composeMutationKey(schema, undefined),
|
|
33
|
+
...filters
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeMutationFilters.cjs","sources":["../../../src/lib/composeMutationFilters.ts"],"sourcesContent":["import type { OperationSchema } from './requestFn.js';\nimport { composeMutationKey } from './composeMutationKey.js';\n\n/**\n * Replaces the `parameters` field in the filters with a `mutationKey` field based on the schema.\n * If no filters are provided, a `mutationKey` will be composed schema's base query key.\n * @param schema\n * @param filters\n */\nexport function composeMutationFilters<Filters extends object>(\n schema: OperationSchema,\n filters: Filters | undefined\n) {\n if (!filters) {\n return {\n mutationKey: composeMutationKey(schema, undefined),\n };\n }\n\n if (filters && 'mutationKey' in filters && 'parameters' in filters) {\n throw new Error(\n `'composeMutationFilters': 'mutationKey' and 'parameters' cannot be used together`\n );\n }\n\n if ('mutationKey' in filters) {\n return filters;\n }\n\n if ('parameters' in filters) {\n const { parameters, ...filtersWithoutParameters } = filters;\n\n Object.assign(filtersWithoutParameters, {\n mutationKey: composeMutationKey(schema, parameters),\n });\n\n return filtersWithoutParameters;\n }\n\n return {\n
|
|
1
|
+
{"version":3,"file":"composeMutationFilters.cjs","sources":["../../../src/lib/composeMutationFilters.ts"],"sourcesContent":["import type { OperationSchema } from './requestFn.js';\nimport { composeMutationKey } from './composeMutationKey.js';\n\n/**\n * Replaces the `parameters` field in the filters with a `mutationKey` field based on the schema.\n * If no filters are provided, a `mutationKey` will be composed schema's base query key.\n * @param schema\n * @param filters\n */\nexport function composeMutationFilters<Filters extends object>(\n schema: OperationSchema,\n filters: Filters | undefined\n) {\n if (!filters) {\n return {\n exact: false,\n mutationKey: composeMutationKey(schema, undefined),\n };\n }\n\n if (filters && 'mutationKey' in filters && 'parameters' in filters) {\n throw new Error(\n `'composeMutationFilters': 'mutationKey' and 'parameters' cannot be used together`\n );\n }\n\n if ('mutationKey' in filters) {\n return filters;\n }\n\n if ('parameters' in filters) {\n const { parameters, ...filtersWithoutParameters } = filters;\n\n Object.assign(filtersWithoutParameters, {\n mutationKey: composeMutationKey(schema, parameters),\n });\n\n return filtersWithoutParameters;\n }\n\n return {\n exact: false,\n mutationKey: composeMutationKey(schema, undefined),\n ...filters,\n };\n}\n"],"names":["composeMutationFilters","schema","filters","exact","mutationKey","composeMutationKey","undefined","Error","parameters","filtersWithoutParameters","Object","assign"],"mappings":";;;;AAGA;;;;;AAKC,IACM,SAASA,sBACdC,CAAAA,MAAuB,EACvBC,OAA4B,EAAA;AAE5B,IAAA,IAAI,CAACA,OAAS,EAAA;QACZ,OAAO;YACLC,KAAO,EAAA,KAAA;AACPC,YAAAA,WAAAA,EAAaC,sCAAmBJ,MAAQK,EAAAA,SAAAA,CAAAA;AAC1C,SAAA,CAAA;AACF,KAAA;AAEA,IAAA,IAAIJ,OAAW,IAAA,aAAA,IAAiBA,OAAW,IAAA,YAAA,IAAgBA,OAAS,EAAA;AAClE,QAAA,MAAM,IAAIK,KAAAA,CACR,CAAC,gFAAgF,CAAC,CAAA,CAAA;AAEtF,KAAA;AAEA,IAAA,IAAI,iBAAiBL,OAAS,EAAA;QAC5B,OAAOA,OAAAA,CAAAA;AACT,KAAA;AAEA,IAAA,IAAI,gBAAgBA,OAAS,EAAA;AAC3B,QAAA,MAAM,EAAEM,UAAU,EAAE,GAAGC,0BAA0B,GAAGP,OAAAA,CAAAA;QAEpDQ,MAAOC,CAAAA,MAAM,CAACF,wBAA0B,EAAA;AACtCL,YAAAA,WAAAA,EAAaC,sCAAmBJ,MAAQO,EAAAA,UAAAA,CAAAA;AAC1C,SAAA,CAAA,CAAA;QAEA,OAAOC,wBAAAA,CAAAA;AACT,KAAA;IAEA,OAAO;QACLN,KAAO,EAAA,KAAA;AACPC,QAAAA,WAAAA,EAAaC,sCAAmBJ,MAAQK,EAAAA,SAAAA,CAAAA;AACxC,QAAA,GAAGJ,OAAO;AACZ,KAAA,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeMutationKey.cjs","sources":["../../../src/lib/composeMutationKey.ts"],"sourcesContent":["import type { ServiceOperationMutationKey } from '@openapi-qraft/tanstack-query-react-types';\nimport type { OperationSchema } from './requestFn.js';\n\n/**\n * Omit `body` or `requestBody` from mutation parameters if exists\n * and return the rest of the parameters\n */\nexport function composeMutationKey<TSchema extends OperationSchema>(\n schema: TSchema,\n parameters: undefined\n): ServiceOperationMutationKey<TSchema, undefined>;\nexport function composeMutationKey<TSchema extends OperationSchema, TParams>(\n schema: TSchema,\n parameters: TParams\n): ServiceOperationMutationKey<TSchema, TParams>;\nexport function composeMutationKey<\n TSchema extends OperationSchema,\n TParams = unknown,\n>(schema: TSchema, parameters: TParams | undefined) {\n return parameters === undefined\n ? [{ url: schema.url, method: schema.method }, {}]\n : [\n {\n url: schema.url,\n method: schema.method,\n },\n omitMutationPayload(parameters),\n ];\n}\n\
|
|
1
|
+
{"version":3,"file":"composeMutationKey.cjs","sources":["../../../src/lib/composeMutationKey.ts"],"sourcesContent":["import type { ServiceOperationMutationKey } from '@openapi-qraft/tanstack-query-react-types';\nimport type { OperationSchema } from './requestFn.js';\n\n/**\n * Omit `body` or `requestBody` from mutation parameters if exists\n * and return the rest of the parameters\n */\nexport function composeMutationKey<TSchema extends OperationSchema>(\n schema: TSchema,\n parameters: undefined\n): ServiceOperationMutationKey<TSchema, undefined>;\nexport function composeMutationKey<TSchema extends OperationSchema, TParams>(\n schema: TSchema,\n parameters: TParams\n): ServiceOperationMutationKey<TSchema, TParams>;\nexport function composeMutationKey<\n TSchema extends OperationSchema,\n TParams = unknown,\n>(schema: TSchema, parameters: TParams | undefined) {\n return parameters === undefined\n ? [{ url: schema.url, method: schema.method }, {}]\n : [\n {\n url: schema.url,\n method: schema.method,\n },\n omitMutationPayload(parameters),\n ];\n}\n\nfunction omitMutationPayload<T>(params: T) {\n if (!params || typeof params !== 'object')\n throw new Error('`params` must be object');\n\n if ('body' in params || 'requestBody' in params) {\n const {\n body: _,\n requestBody: __,\n ...paramsRest\n } = params as Record<'body' | 'requestBody', unknown>;\n return paramsRest;\n }\n\n return params as Omit<T, 'body' | 'requestBody'>;\n}\n"],"names":["composeMutationKey","schema","parameters","undefined","url","method","omitMutationPayload","params","Error","body","_","requestBody","__","paramsRest"],"mappings":";;AAeO,SAASA,kBAAAA,CAGdC,MAAe,EAAEC,UAA+B,EAAA;AAChD,IAAA,OAAOA,eAAeC,SAClB,GAAA;AAAC,QAAA;AAAEC,YAAAA,GAAAA,EAAKH,OAAOG,GAAG;AAAEC,YAAAA,MAAAA,EAAQJ,OAAOI,MAAM;AAAC,SAAA;QAAG,EAAC;KAAE,GAChD;AACE,QAAA;AACED,YAAAA,GAAAA,EAAKH,OAAOG,GAAG;AACfC,YAAAA,MAAAA,EAAQJ,OAAOI,MAAM;AACvB,SAAA;QACAC,mBAAoBJ,CAAAA,UAAAA,CAAAA;AACrB,KAAA,CAAA;AACP,CAAA;AAEA,SAASI,oBAAuBC,MAAS,EAAA;AACvC,IAAA,IAAI,CAACA,MAAU,IAAA,OAAOA,WAAW,QAC/B,EAAA,MAAM,IAAIC,KAAM,CAAA,yBAAA,CAAA,CAAA;IAElB,IAAI,MAAA,IAAUD,MAAU,IAAA,aAAA,IAAiBA,MAAQ,EAAA;QAC/C,MAAM,EACJE,MAAMC,CAAC,EACPC,aAAaC,EAAE,EACf,GAAGC,UAAAA,EACJ,GAAGN,MAAAA,CAAAA;QACJ,OAAOM,UAAAA,CAAAA;AACT,KAAA;IAEA,OAAON,MAAAA,CAAAA;AACT;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { composeMutationFilters } from '../lib/composeMutationFilters.js';
|
|
2
|
+
|
|
3
|
+
function getMutationCache(qraftOptions, schema) {
|
|
4
|
+
const mutationCache = qraftOptions.queryClient.getMutationCache();
|
|
5
|
+
return wrapMutationCacheMethods(schema, mutationCache);
|
|
6
|
+
}
|
|
7
|
+
function wrapMutationCacheMethods(schema, original) {
|
|
8
|
+
return new Proxy(original, {
|
|
9
|
+
get (target, prop, receiver) {
|
|
10
|
+
if (prop === 'find' || prop === 'findAll') {
|
|
11
|
+
return function(...args) {
|
|
12
|
+
return Reflect.apply(target[prop], target, [
|
|
13
|
+
composeMutationFilters(schema, args[0]),
|
|
14
|
+
...args.slice(1, args.length)
|
|
15
|
+
]);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return Reflect.get(target, prop, receiver);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getMutationCache };
|
|
24
|
+
//# sourceMappingURL=getMutationCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMutationCache.js","sources":["../../../src/callbacks/getMutationCache.ts"],"sourcesContent":["import type { OperationSchema } from '@openapi-qraft/tanstack-query-react-types';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport function getMutationCache(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema\n) {\n const mutationCache = qraftOptions.queryClient.getMutationCache();\n\n return wrapMutationCacheMethods(schema, mutationCache);\n}\n\nfunction wrapMutationCacheMethods<\n T extends Record<'find' | 'findAll', (...args: any[]) => any>,\n>(schema: OperationSchema, original: T): T {\n return new Proxy(original, {\n get(target, prop, receiver) {\n if (prop === 'find' || prop === 'findAll') {\n return function (...args: any[]) {\n return Reflect.apply(target[prop], target, [\n composeMutationFilters(schema, args[0] as never),\n ...args.slice(1, args.length),\n ]);\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n"],"names":["getMutationCache","qraftOptions","schema","mutationCache","queryClient","wrapMutationCacheMethods","original","Proxy","get","target","prop","receiver","args","Reflect","apply","composeMutationFilters","slice","length"],"mappings":";;AAIO,SAASA,gBAAAA,CACdC,YAAyC,EACzCC,MAAuB,EAAA;AAEvB,IAAA,MAAMC,aAAgBF,GAAAA,YAAAA,CAAaG,WAAW,CAACJ,gBAAgB,EAAA,CAAA;AAE/D,IAAA,OAAOK,yBAAyBH,MAAQC,EAAAA,aAAAA,CAAAA,CAAAA;AAC1C,CAAA;AAEA,SAASE,wBAAAA,CAEPH,MAAuB,EAAEI,QAAW,EAAA;IACpC,OAAO,IAAIC,MAAMD,QAAU,EAAA;AACzBE,QAAAA,GAAAA,CAAAA,CAAIC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAA;YACxB,IAAID,IAAAA,KAAS,MAAUA,IAAAA,IAAAA,KAAS,SAAW,EAAA;gBACzC,OAAO,SAAU,GAAGE,IAAW,EAAA;AAC7B,oBAAA,OAAOC,QAAQC,KAAK,CAACL,MAAM,CAACC,IAAAA,CAAK,EAAED,MAAQ,EAAA;wBACzCM,sBAAuBb,CAAAA,MAAAA,EAAQU,IAAI,CAAC,CAAE,CAAA,CAAA;AACnCA,wBAAAA,GAAAA,IAAAA,CAAKI,KAAK,CAAC,CAAGJ,EAAAA,IAAAA,CAAKK,MAAM,CAAA;AAC7B,qBAAA,CAAA,CAAA;AACH,iBAAA,CAAA;AACF,aAAA;AAEA,YAAA,OAAOJ,OAAQL,CAAAA,GAAG,CAACC,MAAAA,EAAQC,IAAMC,EAAAA,QAAAA,CAAAA,CAAAA;AACnC,SAAA;AACF,KAAA,CAAA,CAAA;AACF;;;;"}
|
|
@@ -23,6 +23,7 @@ export { removeQueries } from './removeQueries.js';
|
|
|
23
23
|
export { refetchQueries } from './refetchQueries.js';
|
|
24
24
|
export { isFetching } from './isFetching.js';
|
|
25
25
|
export { isMutating } from './isMutating.js';
|
|
26
|
+
export { getMutationCache } from './getMutationCache.js';
|
|
26
27
|
export { useIsFetching } from './useIsFetching.js';
|
|
27
28
|
export { fetchQuery } from './fetchQuery.js';
|
|
28
29
|
export { prefetchQuery } from './prefetchQuery.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -8,6 +8,7 @@ import { composeMutationKey } from './composeMutationKey.js';
|
|
|
8
8
|
*/ function composeMutationFilters(schema, filters) {
|
|
9
9
|
if (!filters) {
|
|
10
10
|
return {
|
|
11
|
+
exact: false,
|
|
11
12
|
mutationKey: composeMutationKey(schema, undefined)
|
|
12
13
|
};
|
|
13
14
|
}
|
|
@@ -25,8 +26,9 @@ import { composeMutationKey } from './composeMutationKey.js';
|
|
|
25
26
|
return filtersWithoutParameters;
|
|
26
27
|
}
|
|
27
28
|
return {
|
|
28
|
-
|
|
29
|
-
mutationKey: composeMutationKey(schema, undefined)
|
|
29
|
+
exact: false,
|
|
30
|
+
mutationKey: composeMutationKey(schema, undefined),
|
|
31
|
+
...filters
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeMutationFilters.js","sources":["../../../src/lib/composeMutationFilters.ts"],"sourcesContent":["import type { OperationSchema } from './requestFn.js';\nimport { composeMutationKey } from './composeMutationKey.js';\n\n/**\n * Replaces the `parameters` field in the filters with a `mutationKey` field based on the schema.\n * If no filters are provided, a `mutationKey` will be composed schema's base query key.\n * @param schema\n * @param filters\n */\nexport function composeMutationFilters<Filters extends object>(\n schema: OperationSchema,\n filters: Filters | undefined\n) {\n if (!filters) {\n return {\n mutationKey: composeMutationKey(schema, undefined),\n };\n }\n\n if (filters && 'mutationKey' in filters && 'parameters' in filters) {\n throw new Error(\n `'composeMutationFilters': 'mutationKey' and 'parameters' cannot be used together`\n );\n }\n\n if ('mutationKey' in filters) {\n return filters;\n }\n\n if ('parameters' in filters) {\n const { parameters, ...filtersWithoutParameters } = filters;\n\n Object.assign(filtersWithoutParameters, {\n mutationKey: composeMutationKey(schema, parameters),\n });\n\n return filtersWithoutParameters;\n }\n\n return {\n
|
|
1
|
+
{"version":3,"file":"composeMutationFilters.js","sources":["../../../src/lib/composeMutationFilters.ts"],"sourcesContent":["import type { OperationSchema } from './requestFn.js';\nimport { composeMutationKey } from './composeMutationKey.js';\n\n/**\n * Replaces the `parameters` field in the filters with a `mutationKey` field based on the schema.\n * If no filters are provided, a `mutationKey` will be composed schema's base query key.\n * @param schema\n * @param filters\n */\nexport function composeMutationFilters<Filters extends object>(\n schema: OperationSchema,\n filters: Filters | undefined\n) {\n if (!filters) {\n return {\n exact: false,\n mutationKey: composeMutationKey(schema, undefined),\n };\n }\n\n if (filters && 'mutationKey' in filters && 'parameters' in filters) {\n throw new Error(\n `'composeMutationFilters': 'mutationKey' and 'parameters' cannot be used together`\n );\n }\n\n if ('mutationKey' in filters) {\n return filters;\n }\n\n if ('parameters' in filters) {\n const { parameters, ...filtersWithoutParameters } = filters;\n\n Object.assign(filtersWithoutParameters, {\n mutationKey: composeMutationKey(schema, parameters),\n });\n\n return filtersWithoutParameters;\n }\n\n return {\n exact: false,\n mutationKey: composeMutationKey(schema, undefined),\n ...filters,\n };\n}\n"],"names":["composeMutationFilters","schema","filters","exact","mutationKey","composeMutationKey","undefined","Error","parameters","filtersWithoutParameters","Object","assign"],"mappings":";;AAGA;;;;;AAKC,IACM,SAASA,sBACdC,CAAAA,MAAuB,EACvBC,OAA4B,EAAA;AAE5B,IAAA,IAAI,CAACA,OAAS,EAAA;QACZ,OAAO;YACLC,KAAO,EAAA,KAAA;AACPC,YAAAA,WAAAA,EAAaC,mBAAmBJ,MAAQK,EAAAA,SAAAA,CAAAA;AAC1C,SAAA,CAAA;AACF,KAAA;AAEA,IAAA,IAAIJ,OAAW,IAAA,aAAA,IAAiBA,OAAW,IAAA,YAAA,IAAgBA,OAAS,EAAA;AAClE,QAAA,MAAM,IAAIK,KAAAA,CACR,CAAC,gFAAgF,CAAC,CAAA,CAAA;AAEtF,KAAA;AAEA,IAAA,IAAI,iBAAiBL,OAAS,EAAA;QAC5B,OAAOA,OAAAA,CAAAA;AACT,KAAA;AAEA,IAAA,IAAI,gBAAgBA,OAAS,EAAA;AAC3B,QAAA,MAAM,EAAEM,UAAU,EAAE,GAAGC,0BAA0B,GAAGP,OAAAA,CAAAA;QAEpDQ,MAAOC,CAAAA,MAAM,CAACF,wBAA0B,EAAA;AACtCL,YAAAA,WAAAA,EAAaC,mBAAmBJ,MAAQO,EAAAA,UAAAA,CAAAA;AAC1C,SAAA,CAAA,CAAA;QAEA,OAAOC,wBAAAA,CAAAA;AACT,KAAA;IAEA,OAAO;QACLN,KAAO,EAAA,KAAA;AACPC,QAAAA,WAAAA,EAAaC,mBAAmBJ,MAAQK,EAAAA,SAAAA,CAAAA;AACxC,QAAA,GAAGJ,OAAO;AACZ,KAAA,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeMutationKey.js","sources":["../../../src/lib/composeMutationKey.ts"],"sourcesContent":["import type { ServiceOperationMutationKey } from '@openapi-qraft/tanstack-query-react-types';\nimport type { OperationSchema } from './requestFn.js';\n\n/**\n * Omit `body` or `requestBody` from mutation parameters if exists\n * and return the rest of the parameters\n */\nexport function composeMutationKey<TSchema extends OperationSchema>(\n schema: TSchema,\n parameters: undefined\n): ServiceOperationMutationKey<TSchema, undefined>;\nexport function composeMutationKey<TSchema extends OperationSchema, TParams>(\n schema: TSchema,\n parameters: TParams\n): ServiceOperationMutationKey<TSchema, TParams>;\nexport function composeMutationKey<\n TSchema extends OperationSchema,\n TParams = unknown,\n>(schema: TSchema, parameters: TParams | undefined) {\n return parameters === undefined\n ? [{ url: schema.url, method: schema.method }, {}]\n : [\n {\n url: schema.url,\n method: schema.method,\n },\n omitMutationPayload(parameters),\n ];\n}\n\
|
|
1
|
+
{"version":3,"file":"composeMutationKey.js","sources":["../../../src/lib/composeMutationKey.ts"],"sourcesContent":["import type { ServiceOperationMutationKey } from '@openapi-qraft/tanstack-query-react-types';\nimport type { OperationSchema } from './requestFn.js';\n\n/**\n * Omit `body` or `requestBody` from mutation parameters if exists\n * and return the rest of the parameters\n */\nexport function composeMutationKey<TSchema extends OperationSchema>(\n schema: TSchema,\n parameters: undefined\n): ServiceOperationMutationKey<TSchema, undefined>;\nexport function composeMutationKey<TSchema extends OperationSchema, TParams>(\n schema: TSchema,\n parameters: TParams\n): ServiceOperationMutationKey<TSchema, TParams>;\nexport function composeMutationKey<\n TSchema extends OperationSchema,\n TParams = unknown,\n>(schema: TSchema, parameters: TParams | undefined) {\n return parameters === undefined\n ? [{ url: schema.url, method: schema.method }, {}]\n : [\n {\n url: schema.url,\n method: schema.method,\n },\n omitMutationPayload(parameters),\n ];\n}\n\nfunction omitMutationPayload<T>(params: T) {\n if (!params || typeof params !== 'object')\n throw new Error('`params` must be object');\n\n if ('body' in params || 'requestBody' in params) {\n const {\n body: _,\n requestBody: __,\n ...paramsRest\n } = params as Record<'body' | 'requestBody', unknown>;\n return paramsRest;\n }\n\n return params as Omit<T, 'body' | 'requestBody'>;\n}\n"],"names":["composeMutationKey","schema","parameters","undefined","url","method","omitMutationPayload","params","Error","body","_","requestBody","__","paramsRest"],"mappings":"AAeO,SAASA,kBAAAA,CAGdC,MAAe,EAAEC,UAA+B,EAAA;AAChD,IAAA,OAAOA,eAAeC,SAClB,GAAA;AAAC,QAAA;AAAEC,YAAAA,GAAAA,EAAKH,OAAOG,GAAG;AAAEC,YAAAA,MAAAA,EAAQJ,OAAOI,MAAM;AAAC,SAAA;QAAG,EAAC;KAAE,GAChD;AACE,QAAA;AACED,YAAAA,GAAAA,EAAKH,OAAOG,GAAG;AACfC,YAAAA,MAAAA,EAAQJ,OAAOI,MAAM;AACvB,SAAA;QACAC,mBAAoBJ,CAAAA,UAAAA,CAAAA;AACrB,KAAA,CAAA;AACP,CAAA;AAEA,SAASI,oBAAuBC,MAAS,EAAA;AACvC,IAAA,IAAI,CAACA,MAAU,IAAA,OAAOA,WAAW,QAC/B,EAAA,MAAM,IAAIC,KAAM,CAAA,yBAAA,CAAA,CAAA;IAElB,IAAI,MAAA,IAAUD,MAAU,IAAA,aAAA,IAAiBA,MAAQ,EAAA;QAC/C,MAAM,EACJE,MAAMC,CAAC,EACPC,aAAaC,EAAE,EACf,GAAGC,UAAAA,EACJ,GAAGN,MAAAA,CAAAA;QACJ,OAAOM,UAAAA,CAAAA;AACT,KAAA;IAEA,OAAON,MAAAA,CAAAA;AACT;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OperationSchema } from '@openapi-qraft/tanstack-query-react-types';
|
|
2
|
+
import type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';
|
|
3
|
+
export declare function getMutationCache(qraftOptions: CreateAPIQueryClientOptions, schema: OperationSchema): import("@tanstack/query-core").MutationCache;
|
|
4
|
+
//# sourceMappingURL=getMutationCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMutationCache.d.ts","sourceRoot":"","sources":["../../../src/callbacks/getMutationCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGxE,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,2BAA2B,EACzC,MAAM,EAAE,eAAe,gDAKxB"}
|
|
@@ -23,6 +23,7 @@ export { removeQueries } from './removeQueries.js';
|
|
|
23
23
|
export { refetchQueries } from './refetchQueries.js';
|
|
24
24
|
export { isFetching } from './isFetching.js';
|
|
25
25
|
export { isMutating } from './isMutating.js';
|
|
26
|
+
export { getMutationCache } from './getMutationCache.js';
|
|
26
27
|
export { useIsFetching } from './useIsFetching.js';
|
|
27
28
|
export { fetchQuery } from './fetchQuery.js';
|
|
28
29
|
export { prefetchQuery } from './prefetchQuery.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/callbacks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAA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} from './requestFn.js';
|
|
|
6
6
|
* @param filters
|
|
7
7
|
*/
|
|
8
8
|
export declare function composeMutationFilters<Filters extends object>(schema: OperationSchema, filters: Filters | undefined): (Filters & Record<"mutationKey", unknown>) | Omit<Filters & Record<"parameters", unknown>, "parameters"> | {
|
|
9
|
+
exact: boolean;
|
|
9
10
|
mutationKey: [OperationSchema];
|
|
10
11
|
};
|
|
11
12
|
//# sourceMappingURL=composeMutationFilters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeMutationFilters.d.ts","sourceRoot":"","sources":["../../../src/lib/composeMutationFilters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,OAAO,GAAG,SAAS
|
|
1
|
+
{"version":3,"file":"composeMutationFilters.d.ts","sourceRoot":"","sources":["../../../src/lib/composeMutationFilters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,OAAO,GAAG,SAAS;;;EAkC7B"}
|
|
@@ -6,5 +6,4 @@ import type { OperationSchema } from './requestFn.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function composeMutationKey<TSchema extends OperationSchema>(schema: TSchema, parameters: undefined): ServiceOperationMutationKey<TSchema, undefined>;
|
|
8
8
|
export declare function composeMutationKey<TSchema extends OperationSchema, TParams>(schema: TSchema, parameters: TParams): ServiceOperationMutationKey<TSchema, TParams>;
|
|
9
|
-
export declare function omitMutationPayload<T>(params: T): {};
|
|
10
9
|
//# sourceMappingURL=composeMutationKey.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeMutationKey.d.ts","sourceRoot":"","sources":["../../../src/lib/composeMutationKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,eAAe,EAChE,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,GACpB,2BAA2B,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACnD,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,eAAe,EAAE,OAAO,EACzE,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,OAAO,GAClB,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"composeMutationKey.d.ts","sourceRoot":"","sources":["../../../src/lib/composeMutationKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,eAAe,EAChE,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,GACpB,2BAA2B,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACnD,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,eAAe,EAAE,OAAO,EACzE,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,OAAO,GAClB,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "OpenAPI client for React, providing type-safe requests and dynamic TanStack Query React Hooks via a modular, Proxy-based architecture.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "NODE_ENV=production rollup --config rollup.config.mjs && tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
@@ -15,18 +15,19 @@
|
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@openapi-qraft/tanstack-query-react-types": "2.
|
|
18
|
+
"@openapi-qraft/tanstack-query-react-types": "2.12.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@tanstack/react-query": "^5.80.0",
|
|
22
22
|
"react": "^18 || ^19"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@openapi-qraft/cli": "2.
|
|
25
|
+
"@openapi-qraft/cli": "2.12.0",
|
|
26
26
|
"@openapi-qraft/eslint-config": "1.0.1",
|
|
27
|
-
"@openapi-qraft/
|
|
27
|
+
"@openapi-qraft/eslint-plugin-query": "2.12.0",
|
|
28
|
+
"@openapi-qraft/openapi-typescript-plugin": "^2.12.0",
|
|
28
29
|
"@openapi-qraft/rollup-config": "1.1.1",
|
|
29
|
-
"@openapi-qraft/tanstack-query-react-plugin": "2.
|
|
30
|
+
"@openapi-qraft/tanstack-query-react-plugin": "2.12.0",
|
|
30
31
|
"@openapi-qraft/test-fixtures": "1.1.1",
|
|
31
32
|
"@tanstack/react-query": "^5.80.6",
|
|
32
33
|
"@testing-library/dom": "^10.4.0",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OperationSchema } from '@openapi-qraft/tanstack-query-react-types';
|
|
2
|
+
import type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';
|
|
3
|
+
import { composeMutationFilters } from '../lib/composeMutationFilters.js';
|
|
4
|
+
|
|
5
|
+
export function getMutationCache(
|
|
6
|
+
qraftOptions: CreateAPIQueryClientOptions,
|
|
7
|
+
schema: OperationSchema
|
|
8
|
+
) {
|
|
9
|
+
const mutationCache = qraftOptions.queryClient.getMutationCache();
|
|
10
|
+
|
|
11
|
+
return wrapMutationCacheMethods(schema, mutationCache);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function wrapMutationCacheMethods<
|
|
15
|
+
T extends Record<'find' | 'findAll', (...args: any[]) => any>,
|
|
16
|
+
>(schema: OperationSchema, original: T): T {
|
|
17
|
+
return new Proxy(original, {
|
|
18
|
+
get(target, prop, receiver) {
|
|
19
|
+
if (prop === 'find' || prop === 'findAll') {
|
|
20
|
+
return function (...args: any[]) {
|
|
21
|
+
return Reflect.apply(target[prop], target, [
|
|
22
|
+
composeMutationFilters(schema, args[0] as never),
|
|
23
|
+
...args.slice(1, args.length),
|
|
24
|
+
]);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Reflect.get(target, prop, receiver);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
package/src/callbacks/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ export { removeQueries } from './removeQueries.js';
|
|
|
23
23
|
export { refetchQueries } from './refetchQueries.js';
|
|
24
24
|
export { isFetching } from './isFetching.js';
|
|
25
25
|
export { isMutating } from './isMutating.js';
|
|
26
|
+
export { getMutationCache } from './getMutationCache.js';
|
|
26
27
|
export { useIsFetching } from './useIsFetching.js';
|
|
27
28
|
export { fetchQuery } from './fetchQuery.js';
|
|
28
29
|
export { prefetchQuery } from './prefetchQuery.js';
|
|
@@ -13,6 +13,7 @@ export function composeMutationFilters<Filters extends object>(
|
|
|
13
13
|
) {
|
|
14
14
|
if (!filters) {
|
|
15
15
|
return {
|
|
16
|
+
exact: false,
|
|
16
17
|
mutationKey: composeMutationKey(schema, undefined),
|
|
17
18
|
};
|
|
18
19
|
}
|
|
@@ -38,7 +39,8 @@ export function composeMutationFilters<Filters extends object>(
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
return {
|
|
41
|
-
|
|
42
|
+
exact: false,
|
|
42
43
|
mutationKey: composeMutationKey(schema, undefined),
|
|
44
|
+
...filters,
|
|
43
45
|
};
|
|
44
46
|
}
|