Skip to content

fix: avoid TypeError when Apollo withDisabledDeprecations is not a function#119

Merged
Chhavi-Mandowara merged 1 commit intodevelopmentfrom
CL-2971
Mar 23, 2026
Merged

fix: avoid TypeError when Apollo withDisabledDeprecations is not a function#119
Chhavi-Mandowara merged 1 commit intodevelopmentfrom
CL-2971

Conversation

@Chhavi-Mandowara
Copy link
Contributor

No description provided.

@Chhavi-Mandowara Chhavi-Mandowara requested review from a team as code owners March 23, 2026 13:09
@Chhavi-Mandowara Chhavi-Mandowara merged commit 068c11a into development Mar 23, 2026
6 checks passed
@Chhavi-Mandowara Chhavi-Mandowara deleted the CL-2971 branch March 23, 2026 13:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the log polling utilities against Apollo Client versions/builds where @apollo/client/utilities/deprecation either can’t be required or does not export withDisabledDeprecations as a callable function, preventing a runtime TypeError during log polling.

Changes:

  • Adds a Node createRequire-based import path to load Apollo’s deprecation utility more defensively.
  • Guards execution so withDisabledDeprecations is only invoked when it’s actually a function, otherwise falls back to executing the wrapped function normally.
  • Minor refactors/formatting in watchQuery call sites and catch blocks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +75
} catch {
void 0;
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void 0; in this catch block will likely trip ESLint's no-unused-expressions (enabled via eslint:recommended) and fails linting. Prefer an empty catch {} (if allowed) or add a comment / explicit handling instead of a no-op expression statement.

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +84
} catch {
void 0;
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: void 0; inside catch is an unused expression and is likely to fail no-unused-expressions. Use an empty catch or a comment / minimal handling instead.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +96
} catch {
void 0;
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: void 0; is a no-op expression statement and may be flagged by no-unused-expressions. Prefer catch {} (or a short comment) to intentionally swallow the error.

Copilot uses AI. Check for mistakes.
return fn();
}

const handler = (withDisabledDeprecations as () => unknown)();
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new guard that falls back when withDisabledDeprecations is missing or not a function is the core of this fix, but it isn’t covered by tests. Please add a regression test that simulates the module exporting a non-function (or missing) withDisabledDeprecations and asserts withDeprecationsDisabled still runs fn() without throwing.

Suggested change
const handler = (withDisabledDeprecations as () => unknown)();
let handler: unknown;
try {
handler = (withDisabledDeprecations as () => unknown)();
} catch {
// If setting up the deprecation handler fails, fall back to running fn without it.
return fn();
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants