@memberjunction/server 2.121.0 → 2.122.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.
@@ -1,276 +1,276 @@
1
- import { Arg, Ctx, ObjectType, Query, Resolver, Field, Int } from 'type-graphql';
2
- import { RunQuery, QueryInfo, IRunQueryProvider, IMetadataProvider } from '@memberjunction/core';
3
- import { AppContext } from '../types.js';
4
- import { RequireSystemUser } from '../directives/RequireSystemUser.js';
5
- import { GraphQLJSONObject } from 'graphql-type-json';
6
- import { Metadata } from '@memberjunction/core';
7
- import { GetReadOnlyProvider } from '../util.js';
8
-
9
- @ObjectType()
10
- export class RunQueryResultType {
11
- @Field()
12
- QueryID: string;
13
-
14
- @Field()
15
- QueryName: string;
16
-
17
- @Field()
18
- Success: boolean;
19
-
20
- @Field()
21
- Results: string;
22
-
23
- @Field()
24
- RowCount: number;
25
-
26
- @Field()
27
- TotalRowCount: number;
28
-
29
- @Field()
30
- ExecutionTime: number;
31
-
32
- @Field()
33
- ErrorMessage: string;
34
-
35
- @Field(() => String, { nullable: true })
36
- AppliedParameters?: string;
37
-
38
- @Field(() => Boolean, { nullable: true })
39
- CacheHit?: boolean;
40
-
41
- @Field(() => Int, { nullable: true })
42
- CacheTTLRemaining?: number;
43
- }
44
-
45
- @Resolver()
46
- export class RunQueryResolver {
47
- private async findQuery(md: IMetadataProvider, QueryID: string, QueryName?: string, CategoryID?: string, CategoryPath?: string, refreshMetadataIfNotFound: boolean = false): Promise<QueryInfo | null> {
48
- // Filter queries based on provided criteria
49
- const queries = md.Queries.filter(q => {
50
- if (QueryID) {
51
- return q.ID.trim().toLowerCase() === QueryID.trim().toLowerCase();
52
- } else if (QueryName) {
53
- let matches = q.Name.trim().toLowerCase() === QueryName.trim().toLowerCase();
54
- if (CategoryID) {
55
- matches = matches && q.CategoryID?.trim().toLowerCase() === CategoryID.trim().toLowerCase();
56
- }
57
- if (CategoryPath) {
58
- matches = matches && q.Category?.trim().toLowerCase() === CategoryPath.trim().toLowerCase();
59
- }
60
- return matches;
61
- }
62
- return false;
63
- });
64
-
65
- if (queries.length === 0) {
66
- if (refreshMetadataIfNotFound) {
67
- // If we didn't find the query, refresh metadata and try again
68
- await md.Refresh();
69
- return this.findQuery(md, QueryID, QueryName, CategoryID, CategoryPath, false); // change the refresh flag to false so we don't loop infinitely
70
- }
71
- else {
72
- return null; // No query found and not refreshing metadata
73
- }
74
- }
75
- else {
76
- return queries[0];
77
- }
78
- }
79
- @Query(() => RunQueryResultType)
80
- async GetQueryData(@Arg('QueryID', () => String) QueryID: string,
81
- @Ctx() context: AppContext,
82
- @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
83
- @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
84
- @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
85
- @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
86
- @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
87
- @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
88
- @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
89
- const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
90
- const md = provider as unknown as IMetadataProvider;
91
- const rq = new RunQuery(provider as unknown as IRunQueryProvider);
92
- console.log('GetQueryData called with:', { QueryID, Parameters, MaxRows, StartRow, ForceAuditLog, AuditLogDescription });
93
- const result = await rq.RunQuery(
94
- {
95
- QueryID: QueryID,
96
- CategoryID: CategoryID,
97
- CategoryPath: CategoryPath,
98
- Parameters: Parameters,
99
- MaxRows: MaxRows,
100
- StartRow: StartRow,
101
- ForceAuditLog: ForceAuditLog,
102
- AuditLogDescription: AuditLogDescription
103
- },
104
- context.userPayload.userRecord);
105
- console.log('RunQuery result:', {
106
- Success: result.Success,
107
- ErrorMessage: result.ErrorMessage,
108
- AppliedParameters: result.AppliedParameters
109
- });
110
-
111
- // If QueryName is not populated by the provider, use efficient lookup
112
- let queryName = result.QueryName;
113
- if (!queryName) {
114
- try {
115
- const queryInfo = await this.findQuery(md, QueryID, undefined, CategoryID, CategoryPath, true);
116
- if (queryInfo) {
117
- queryName = queryInfo.Name;
118
- }
119
- } catch (error) {
120
- console.error('Error finding query to get name:', error);
121
- }
122
- }
123
-
124
- return {
125
- QueryID: QueryID,
126
- QueryName: queryName || 'Unknown Query',
127
- Success: result.Success ?? false,
128
- Results: JSON.stringify(result.Results ?? null),
129
- RowCount: result.RowCount ?? 0,
130
- TotalRowCount: result.TotalRowCount ?? 0,
131
- ExecutionTime: result.ExecutionTime ?? 0,
132
- ErrorMessage: result.ErrorMessage || '',
133
- AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
134
- CacheHit: (result as any).CacheHit,
135
- CacheTTLRemaining: (result as any).CacheTTLRemaining
136
- };
137
- }
138
-
139
- @Query(() => RunQueryResultType)
140
- async GetQueryDataByName(@Arg('QueryName', () => String) QueryName: string,
141
- @Ctx() context: AppContext,
142
- @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
143
- @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
144
- @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
145
- @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
146
- @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
147
- @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
148
- @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
149
- const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
150
- const rq = new RunQuery(provider as unknown as IRunQueryProvider);
151
- const result = await rq.RunQuery(
152
- {
153
- QueryName: QueryName,
154
- CategoryID: CategoryID,
155
- CategoryPath: CategoryPath,
156
- Parameters: Parameters,
157
- MaxRows: MaxRows,
158
- StartRow: StartRow,
159
- ForceAuditLog: ForceAuditLog,
160
- AuditLogDescription: AuditLogDescription
161
- },
162
- context.userPayload.userRecord);
163
-
164
- return {
165
- QueryID: result.QueryID || '',
166
- QueryName: QueryName,
167
- Success: result.Success ?? false,
168
- Results: JSON.stringify(result.Results ?? null),
169
- RowCount: result.RowCount ?? 0,
170
- TotalRowCount: result.TotalRowCount ?? 0,
171
- ExecutionTime: result.ExecutionTime ?? 0,
172
- ErrorMessage: result.ErrorMessage || '',
173
- AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
174
- CacheHit: (result as any).CacheHit,
175
- CacheTTLRemaining: (result as any).CacheTTLRemaining
176
- };
177
- }
178
-
179
- @RequireSystemUser()
180
- @Query(() => RunQueryResultType)
181
- async GetQueryDataSystemUser(@Arg('QueryID', () => String) QueryID: string,
182
- @Ctx() context: AppContext,
183
- @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
184
- @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
185
- @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
186
- @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
187
- @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
188
- @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
189
- @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
190
- const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
191
- const md = provider as unknown as IMetadataProvider;
192
- const rq = new RunQuery(provider as unknown as IRunQueryProvider);
193
-
194
- const result = await rq.RunQuery(
195
- {
196
- QueryID: QueryID,
197
- CategoryID: CategoryID,
198
- CategoryPath: CategoryPath,
199
- Parameters: Parameters,
200
- MaxRows: MaxRows,
201
- StartRow: StartRow,
202
- ForceAuditLog: ForceAuditLog,
203
- AuditLogDescription: AuditLogDescription
204
- },
205
- context.userPayload.userRecord);
206
-
207
- // If QueryName is not populated by the provider, use efficient lookup
208
- let queryName = result.QueryName;
209
- if (!queryName) {
210
- try {
211
- const queryInfo = await this.findQuery(md, QueryID, undefined, CategoryID, CategoryPath, true);
212
- if (queryInfo) {
213
- queryName = queryInfo.Name;
214
- }
215
- } catch (error) {
216
- console.error('Error finding query to get name:', error);
217
- }
218
- }
219
-
220
- return {
221
- QueryID: QueryID,
222
- QueryName: queryName || 'Unknown Query',
223
- Success: result.Success ?? false,
224
- Results: JSON.stringify(result.Results ?? null),
225
- RowCount: result.RowCount ?? 0,
226
- TotalRowCount: result.TotalRowCount ?? 0,
227
- ExecutionTime: result.ExecutionTime ?? 0,
228
- ErrorMessage: result.ErrorMessage || '',
229
- AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
230
- CacheHit: (result as any).CacheHit,
231
- CacheTTLRemaining: (result as any).CacheTTLRemaining
232
- };
233
- }
234
-
235
- @RequireSystemUser()
236
- @Query(() => RunQueryResultType)
237
- async GetQueryDataByNameSystemUser(@Arg('QueryName', () => String) QueryName: string,
238
- @Ctx() context: AppContext,
239
- @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
240
- @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
241
- @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
242
- @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
243
- @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
244
- @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
245
- @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
246
- const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
247
- const rq = new RunQuery(provider as unknown as IRunQueryProvider);
248
-
249
- const result = await rq.RunQuery(
250
- {
251
- QueryName: QueryName,
252
- CategoryID: CategoryID,
253
- CategoryPath: CategoryPath,
254
- Parameters: Parameters,
255
- MaxRows: MaxRows,
256
- StartRow: StartRow,
257
- ForceAuditLog: ForceAuditLog,
258
- AuditLogDescription: AuditLogDescription
259
- },
260
- context.userPayload.userRecord);
261
-
262
- return {
263
- QueryID: result.QueryID || '',
264
- QueryName: QueryName,
265
- Success: result.Success ?? false,
266
- Results: JSON.stringify(result.Results ?? null),
267
- RowCount: result.RowCount ?? 0,
268
- TotalRowCount: result.TotalRowCount ?? 0,
269
- ExecutionTime: result.ExecutionTime ?? 0,
270
- ErrorMessage: result.ErrorMessage || '',
271
- AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
272
- CacheHit: (result as any).CacheHit,
273
- CacheTTLRemaining: (result as any).CacheTTLRemaining
274
- };
275
- }
1
+ import { Arg, Ctx, ObjectType, Query, Resolver, Field, Int } from 'type-graphql';
2
+ import { RunQuery, QueryInfo, IRunQueryProvider, IMetadataProvider } from '@memberjunction/core';
3
+ import { AppContext } from '../types.js';
4
+ import { RequireSystemUser } from '../directives/RequireSystemUser.js';
5
+ import { GraphQLJSONObject } from 'graphql-type-json';
6
+ import { Metadata } from '@memberjunction/core';
7
+ import { GetReadOnlyProvider } from '../util.js';
8
+
9
+ @ObjectType()
10
+ export class RunQueryResultType {
11
+ @Field()
12
+ QueryID: string;
13
+
14
+ @Field()
15
+ QueryName: string;
16
+
17
+ @Field()
18
+ Success: boolean;
19
+
20
+ @Field()
21
+ Results: string;
22
+
23
+ @Field()
24
+ RowCount: number;
25
+
26
+ @Field()
27
+ TotalRowCount: number;
28
+
29
+ @Field()
30
+ ExecutionTime: number;
31
+
32
+ @Field()
33
+ ErrorMessage: string;
34
+
35
+ @Field(() => String, { nullable: true })
36
+ AppliedParameters?: string;
37
+
38
+ @Field(() => Boolean, { nullable: true })
39
+ CacheHit?: boolean;
40
+
41
+ @Field(() => Int, { nullable: true })
42
+ CacheTTLRemaining?: number;
43
+ }
44
+
45
+ @Resolver()
46
+ export class RunQueryResolver {
47
+ private async findQuery(md: IMetadataProvider, QueryID: string, QueryName?: string, CategoryID?: string, CategoryPath?: string, refreshMetadataIfNotFound: boolean = false): Promise<QueryInfo | null> {
48
+ // Filter queries based on provided criteria
49
+ const queries = md.Queries.filter(q => {
50
+ if (QueryID) {
51
+ return q.ID.trim().toLowerCase() === QueryID.trim().toLowerCase();
52
+ } else if (QueryName) {
53
+ let matches = q.Name.trim().toLowerCase() === QueryName.trim().toLowerCase();
54
+ if (CategoryID) {
55
+ matches = matches && q.CategoryID?.trim().toLowerCase() === CategoryID.trim().toLowerCase();
56
+ }
57
+ if (CategoryPath) {
58
+ matches = matches && q.Category?.trim().toLowerCase() === CategoryPath.trim().toLowerCase();
59
+ }
60
+ return matches;
61
+ }
62
+ return false;
63
+ });
64
+
65
+ if (queries.length === 0) {
66
+ if (refreshMetadataIfNotFound) {
67
+ // If we didn't find the query, refresh metadata and try again
68
+ await md.Refresh();
69
+ return this.findQuery(md, QueryID, QueryName, CategoryID, CategoryPath, false); // change the refresh flag to false so we don't loop infinitely
70
+ }
71
+ else {
72
+ return null; // No query found and not refreshing metadata
73
+ }
74
+ }
75
+ else {
76
+ return queries[0];
77
+ }
78
+ }
79
+ @Query(() => RunQueryResultType)
80
+ async GetQueryData(@Arg('QueryID', () => String) QueryID: string,
81
+ @Ctx() context: AppContext,
82
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
83
+ @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
84
+ @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
85
+ @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
86
+ @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
87
+ @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
88
+ @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
89
+ const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
90
+ const md = provider as unknown as IMetadataProvider;
91
+ const rq = new RunQuery(provider as unknown as IRunQueryProvider);
92
+ console.log('GetQueryData called with:', { QueryID, Parameters, MaxRows, StartRow, ForceAuditLog, AuditLogDescription });
93
+ const result = await rq.RunQuery(
94
+ {
95
+ QueryID: QueryID,
96
+ CategoryID: CategoryID,
97
+ CategoryPath: CategoryPath,
98
+ Parameters: Parameters,
99
+ MaxRows: MaxRows,
100
+ StartRow: StartRow,
101
+ ForceAuditLog: ForceAuditLog,
102
+ AuditLogDescription: AuditLogDescription
103
+ },
104
+ context.userPayload.userRecord);
105
+ console.log('RunQuery result:', {
106
+ Success: result.Success,
107
+ ErrorMessage: result.ErrorMessage,
108
+ AppliedParameters: result.AppliedParameters
109
+ });
110
+
111
+ // If QueryName is not populated by the provider, use efficient lookup
112
+ let queryName = result.QueryName;
113
+ if (!queryName) {
114
+ try {
115
+ const queryInfo = await this.findQuery(md, QueryID, undefined, CategoryID, CategoryPath, true);
116
+ if (queryInfo) {
117
+ queryName = queryInfo.Name;
118
+ }
119
+ } catch (error) {
120
+ console.error('Error finding query to get name:', error);
121
+ }
122
+ }
123
+
124
+ return {
125
+ QueryID: QueryID,
126
+ QueryName: queryName || 'Unknown Query',
127
+ Success: result.Success ?? false,
128
+ Results: JSON.stringify(result.Results ?? null),
129
+ RowCount: result.RowCount ?? 0,
130
+ TotalRowCount: result.TotalRowCount ?? 0,
131
+ ExecutionTime: result.ExecutionTime ?? 0,
132
+ ErrorMessage: result.ErrorMessage || '',
133
+ AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
134
+ CacheHit: (result as any).CacheHit,
135
+ CacheTTLRemaining: (result as any).CacheTTLRemaining
136
+ };
137
+ }
138
+
139
+ @Query(() => RunQueryResultType)
140
+ async GetQueryDataByName(@Arg('QueryName', () => String) QueryName: string,
141
+ @Ctx() context: AppContext,
142
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
143
+ @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
144
+ @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
145
+ @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
146
+ @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
147
+ @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
148
+ @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
149
+ const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
150
+ const rq = new RunQuery(provider as unknown as IRunQueryProvider);
151
+ const result = await rq.RunQuery(
152
+ {
153
+ QueryName: QueryName,
154
+ CategoryID: CategoryID,
155
+ CategoryPath: CategoryPath,
156
+ Parameters: Parameters,
157
+ MaxRows: MaxRows,
158
+ StartRow: StartRow,
159
+ ForceAuditLog: ForceAuditLog,
160
+ AuditLogDescription: AuditLogDescription
161
+ },
162
+ context.userPayload.userRecord);
163
+
164
+ return {
165
+ QueryID: result.QueryID || '',
166
+ QueryName: QueryName,
167
+ Success: result.Success ?? false,
168
+ Results: JSON.stringify(result.Results ?? null),
169
+ RowCount: result.RowCount ?? 0,
170
+ TotalRowCount: result.TotalRowCount ?? 0,
171
+ ExecutionTime: result.ExecutionTime ?? 0,
172
+ ErrorMessage: result.ErrorMessage || '',
173
+ AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
174
+ CacheHit: (result as any).CacheHit,
175
+ CacheTTLRemaining: (result as any).CacheTTLRemaining
176
+ };
177
+ }
178
+
179
+ @RequireSystemUser()
180
+ @Query(() => RunQueryResultType)
181
+ async GetQueryDataSystemUser(@Arg('QueryID', () => String) QueryID: string,
182
+ @Ctx() context: AppContext,
183
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
184
+ @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
185
+ @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
186
+ @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
187
+ @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
188
+ @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
189
+ @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
190
+ const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
191
+ const md = provider as unknown as IMetadataProvider;
192
+ const rq = new RunQuery(provider as unknown as IRunQueryProvider);
193
+
194
+ const result = await rq.RunQuery(
195
+ {
196
+ QueryID: QueryID,
197
+ CategoryID: CategoryID,
198
+ CategoryPath: CategoryPath,
199
+ Parameters: Parameters,
200
+ MaxRows: MaxRows,
201
+ StartRow: StartRow,
202
+ ForceAuditLog: ForceAuditLog,
203
+ AuditLogDescription: AuditLogDescription
204
+ },
205
+ context.userPayload.userRecord);
206
+
207
+ // If QueryName is not populated by the provider, use efficient lookup
208
+ let queryName = result.QueryName;
209
+ if (!queryName) {
210
+ try {
211
+ const queryInfo = await this.findQuery(md, QueryID, undefined, CategoryID, CategoryPath, true);
212
+ if (queryInfo) {
213
+ queryName = queryInfo.Name;
214
+ }
215
+ } catch (error) {
216
+ console.error('Error finding query to get name:', error);
217
+ }
218
+ }
219
+
220
+ return {
221
+ QueryID: QueryID,
222
+ QueryName: queryName || 'Unknown Query',
223
+ Success: result.Success ?? false,
224
+ Results: JSON.stringify(result.Results ?? null),
225
+ RowCount: result.RowCount ?? 0,
226
+ TotalRowCount: result.TotalRowCount ?? 0,
227
+ ExecutionTime: result.ExecutionTime ?? 0,
228
+ ErrorMessage: result.ErrorMessage || '',
229
+ AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
230
+ CacheHit: (result as any).CacheHit,
231
+ CacheTTLRemaining: (result as any).CacheTTLRemaining
232
+ };
233
+ }
234
+
235
+ @RequireSystemUser()
236
+ @Query(() => RunQueryResultType)
237
+ async GetQueryDataByNameSystemUser(@Arg('QueryName', () => String) QueryName: string,
238
+ @Ctx() context: AppContext,
239
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
240
+ @Arg('CategoryPath', () => String, {nullable: true}) CategoryPath?: string,
241
+ @Arg('Parameters', () => GraphQLJSONObject, {nullable: true}) Parameters?: Record<string, any>,
242
+ @Arg('MaxRows', () => Int, {nullable: true}) MaxRows?: number,
243
+ @Arg('StartRow', () => Int, {nullable: true}) StartRow?: number,
244
+ @Arg('ForceAuditLog', () => Boolean, {nullable: true}) ForceAuditLog?: boolean,
245
+ @Arg('AuditLogDescription', () => String, {nullable: true}) AuditLogDescription?: string): Promise<RunQueryResultType> {
246
+ const provider = GetReadOnlyProvider(context.providers, {allowFallbackToReadWrite: true});
247
+ const rq = new RunQuery(provider as unknown as IRunQueryProvider);
248
+
249
+ const result = await rq.RunQuery(
250
+ {
251
+ QueryName: QueryName,
252
+ CategoryID: CategoryID,
253
+ CategoryPath: CategoryPath,
254
+ Parameters: Parameters,
255
+ MaxRows: MaxRows,
256
+ StartRow: StartRow,
257
+ ForceAuditLog: ForceAuditLog,
258
+ AuditLogDescription: AuditLogDescription
259
+ },
260
+ context.userPayload.userRecord);
261
+
262
+ return {
263
+ QueryID: result.QueryID || '',
264
+ QueryName: QueryName,
265
+ Success: result.Success ?? false,
266
+ Results: JSON.stringify(result.Results ?? null),
267
+ RowCount: result.RowCount ?? 0,
268
+ TotalRowCount: result.TotalRowCount ?? 0,
269
+ ExecutionTime: result.ExecutionTime ?? 0,
270
+ ErrorMessage: result.ErrorMessage || '',
271
+ AppliedParameters: result.AppliedParameters ? JSON.stringify(result.AppliedParameters) : undefined,
272
+ CacheHit: (result as any).CacheHit,
273
+ CacheTTLRemaining: (result as any).CacheTTLRemaining
274
+ };
275
+ }
276
276
  }