Skip to content

Commit bf213c0

Browse files
committed
refactor(datastore): remove duplicate subscription variable filtering logic
The reserved keys filtering logic was duplicated between utils.ts and subscription.ts. Since processSubscriptionVariables() in utils.ts already handles sanitization and filtering of reserved GraphQL keywords, the duplicate logic in subscription.ts is unnecessary. This reduces code duplication and ensures consistency in how subscription variables are processed across the codebase. All 12 subscription variables tests continue to pass.
1 parent 73349da commit bf213c0

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

packages/datastore/src/sync/processors/subscription.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -402,52 +402,7 @@ class SubscriptionProcessor {
402402
: undefined;
403403

404404
if (customVars) {
405-
// Check for reserved keys that would conflict
406-
const reservedKeys = [
407-
'filter',
408-
'owner',
409-
'limit',
410-
'nextToken',
411-
'sortDirection',
412-
];
413-
414-
const safeVars: Record<string, any> = {};
415-
let hasConflicts = false;
416-
417-
// Safe iteration that handles Object.create(null)
418-
try {
419-
for (const [key, value] of Object.entries(customVars)) {
420-
if (reservedKeys.includes(key)) {
421-
hasConflicts = true;
422-
} else {
423-
safeVars[key] = value;
424-
}
425-
}
426-
} catch (entriesError) {
427-
// Fallback for objects without prototype
428-
for (const key in customVars) {
429-
if (
430-
Object.prototype.hasOwnProperty.call(
431-
customVars,
432-
key,
433-
)
434-
) {
435-
if (reservedKeys.includes(key)) {
436-
hasConflicts = true;
437-
} else {
438-
safeVars[key] = customVars[key];
439-
}
440-
}
441-
}
442-
}
443-
444-
if (hasConflicts) {
445-
logger.warn(
446-
`subscriptionVariables for ${modelDefinition.name} contains reserved keys that were filtered out`,
447-
);
448-
}
449-
450-
Object.assign(variables, safeVars);
405+
Object.assign(variables, customVars);
451406
}
452407

453408
if (addFilter && predicatesGroup) {

0 commit comments

Comments
 (0)