|
1 | | -import { INVALIDATE_QUERIES, QUERY_OPTIONS_TYPES } from "../const/deps.const"; |
| 1 | +import { MUTATION_EFFECTS, QUERY_MODULE_ENUM, QUERY_OPTIONS_TYPES } from "../const/deps.const"; |
2 | 2 | import { AXIOS_DEFAULT_IMPORT_NAME, AXIOS_IMPORT, AXIOS_REQUEST_CONFIG_TYPE } from "../const/endpoints.const"; |
3 | 3 | import { QUERIES_MODULE_NAME, QUERY_HOOKS, QUERY_IMPORT } from "../const/queries.const"; |
4 | 4 | import { EndpointParameter } from "../types/endpoint"; |
5 | 5 | import { GenerateType, GenerateTypeParams, Import } from "../types/generate"; |
6 | 6 | import { getUniqueArray } from "../utils/array.utils"; |
7 | 7 | import { getEndpointsImports, getModelsImports } from "../utils/generate/generate.imports.utils"; |
8 | 8 | import { |
9 | | - getInvalidateQueriesImportPath, |
| 9 | + getMutationEffectsImportPath, |
10 | 10 | getNamespaceName, |
| 11 | + getQueryModulesImportPath, |
11 | 12 | getQueryTypesImportPath, |
12 | 13 | } from "../utils/generate/generate.utils"; |
13 | 14 | import { getHbsTemplateDelegate } from "../utils/hbs/hbs-template.utils"; |
@@ -37,17 +38,21 @@ export function generateQueries({ resolver, data, tag = "" }: GenerateTypeParams |
37 | 38 | bindings: [ |
38 | 39 | ...(queryEndpoints.length > 0 ? [QUERY_HOOKS.query] : []), |
39 | 40 | ...(resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? [QUERY_HOOKS.infiniteQuery] : []), |
40 | | - ...(mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation, QUERY_HOOKS.queryClient] : []), |
| 41 | + ...(mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : []), |
41 | 42 | ], |
42 | 43 | from: QUERY_IMPORT.from, |
43 | 44 | }; |
44 | 45 |
|
45 | | - const invalidateQueriesImport: Import = { |
46 | | - bindings: [ |
47 | | - INVALIDATE_QUERIES.queryModuleEnum, |
48 | | - ...(mutationEndpoints.length > 0 ? [INVALIDATE_QUERIES.optionsType, INVALIDATE_QUERIES.functionName] : []), |
49 | | - ], |
50 | | - from: getInvalidateQueriesImportPath(resolver.options), |
| 46 | + const hasMutationEffects = resolver.options.mutationEffects; |
| 47 | + const queryModulesImport: Import = { |
| 48 | + bindings: [QUERY_MODULE_ENUM], |
| 49 | + from: getQueryModulesImportPath(resolver.options), |
| 50 | + }; |
| 51 | + |
| 52 | + const hasMutationEffectsImport = hasMutationEffects && mutationEndpoints.length > 0; |
| 53 | + const mutationEffectsImport: Import = { |
| 54 | + bindings: [...(mutationEndpoints.length > 0 ? [MUTATION_EFFECTS.optionsType, MUTATION_EFFECTS.hookName] : [])], |
| 55 | + from: getMutationEffectsImportPath(resolver.options), |
51 | 56 | }; |
52 | 57 |
|
53 | 58 | const queryTypesImport: Import = { |
@@ -80,16 +85,18 @@ export function generateQueries({ resolver, data, tag = "" }: GenerateTypeParams |
80 | 85 | hasAxiosImport, |
81 | 86 | axiosImport, |
82 | 87 | queryImport, |
83 | | - hasInvalidateQueryOptions: resolver.options.invalidateQueryOptions, |
84 | | - invalidateQueriesImport, |
| 88 | + hasMutationEffects, |
| 89 | + queryModulesImport, |
| 90 | + hasMutationEffectsImport, |
| 91 | + mutationEffectsImport, |
85 | 92 | queryTypesImport, |
86 | 93 | modelsImports, |
87 | 94 | endpointsImports, |
88 | 95 | includeNamespace: resolver.options.tsNamespaces, |
89 | 96 | tag, |
90 | 97 | namespace: getNamespaceName({ type: GenerateType.Queries, tag, options: resolver.options }), |
91 | 98 | queriesModuleName: QUERIES_MODULE_NAME, |
92 | | - queryModuleEnum: INVALIDATE_QUERIES.queryModuleEnum, |
| 99 | + queryModuleEnum: QUERY_MODULE_ENUM, |
93 | 100 | endpoints, |
94 | 101 | queryEndpoints, |
95 | 102 | }); |
|
0 commit comments