Skip to content

Commit 69a8642

Browse files
committed
refactor: remove @ts-ignore, fix selector for regex according to RegExpAsString custom scalar deserialization
1 parent c482031 commit 69a8642

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

src/resolvers/helpers/filterOperators.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,19 @@ export function _recurseSchema(
136136
// alias
137137
const fullPath = pathName ? `${pathName}.${fieldName}` : fieldName;
138138
let schemaType;
139-
if (schema) {
140-
// @ts-ignore
141-
if (schema.pathType) {
142-
// @ts-ignore
143-
const pathType = schema.pathType(fullPath);
144-
// @ts-ignore
145-
schemaType = schema.path(fullPath);
146-
// @ts-ignore
147-
if (pathType === 'virtual') schemaType = schema.virtualpath(fullPath);
139+
const _schema = schema as any;
140+
if (_schema) {
141+
if (_schema.pathType) {
142+
const pathType = _schema.pathType(fullPath);
143+
schemaType = _schema.path(fullPath);
144+
if (pathType === 'virtual') schemaType = _schema.virtualpath(fullPath);
148145
if (pathType === 'nested') schemaType = null;
149-
// @ts-ignore
150-
} else if (typeof schema.path === 'string') {
146+
} else if (typeof _schema.path === 'string') {
151147
schemaType = null; // array
152148
}
153149
}
154150

155151
// Need to dig into this space
156-
// @ts-ignore
157152
const isIndexed: boolean = schemaType?.options?.index || fieldName === '_id';
158153

159154
const hasOperatorsConfig =
@@ -181,12 +176,11 @@ export function _recurseSchema(
181176

182177
_recurseSchema(
183178
newITC,
184-
// @ts-ignore
185-
fieldTC,
179+
fieldTC as InputTypeComposer,
186180
`${upperFirst(fieldName)}${typeName}`,
187181
schemaType || schema,
188182
`${fieldName}`,
189-
operatorsConfig,
183+
operatorsConfig as FilterOperatorsOpts,
190184
onlyIndexed
191185
);
192186
if ((onlyIndexed && isIndexed) || hasOperatorsConfig || !operatorsOpts) {
@@ -241,18 +235,12 @@ export const _recurseFields = (fields: SelectorOptions): SelectorOptions => {
241235
const operators: string[] = Object.values(availableOperators);
242236
if (operators.includes(fieldName)) {
243237
if (fieldName === 'regex') {
244-
selectors[`$${fieldName}`] = new RegExp(
245-
// @ts-ignore
246-
fields[`${fieldName}`].match,
247-
// @ts-ignore
248-
fields[`${fieldName}`].options
249-
);
238+
selectors[`$${fieldName}`] = fields[fieldName];
250239
} else {
251240
selectors[`$${fieldName}`] = fields[fieldName];
252241
}
253242
} else {
254-
// @ts-ignore
255-
selectors[fieldName] = _recurseFields(fields[fieldName]);
243+
selectors[fieldName] = _recurseFields(fields[fieldName] as SelectorOptions);
256244
}
257245
});
258246
} else if (Array.isArray(fields)) {
@@ -273,18 +261,15 @@ export function processFilterOperators(filter: Record<string, any>): SelectorOpt
273261
if (filter[OPERATORS_FIELDNAME]) {
274262
const operatorFields = filter[OPERATORS_FIELDNAME];
275263
Object.keys(operatorFields).forEach((fieldName) => {
276-
// eslint-disable-next-line no-param-reassign
277264
filter[fieldName] = _recurseFields(operatorFields[fieldName]);
278265
});
279-
// eslint-disable-next-line no-param-reassign
280266
delete filter[OPERATORS_FIELDNAME];
281267
}
282268

283269
return filter;
284270
}
285271

286272
export function _prepareAndOrFilter(filter: Record<'OR' | 'AND' | '$or' | '$and', any>): void {
287-
/* eslint-disable no-param-reassign */
288273
if (!filter.OR && !filter.AND) return;
289274

290275
const { OR, AND } = filter;
@@ -305,5 +290,4 @@ export function _prepareAndOrFilter(filter: Record<'OR' | 'AND' | '$or' | '$and'
305290
filter.$and = $and;
306291
delete filter.AND;
307292
}
308-
/* eslint-enable no-param-reassign */
309293
}

0 commit comments

Comments
 (0)