Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow suppressing invariant log messages #11655

Closed

Conversation

iiroj
Copy link

@iiroj iiroj commented Mar 9, 2024

Hello,

as a happy user of Apollo Client, I would like to completely suppress the invariant log errors in my production environment. I don't want to load all the error codes into the bundle, nor do I want to output the fallback message linking to https://go.apollo.dev/ into the console.

I opened this small PR that adds a new method for achieving this:

import { setVerbosity } from "@apollo/client/dev";

if (!__DEV__) {  // Silence messages when not in a dev environment
  setVerbosity("silent");
}

Where setVerbosity is just directly re-exported from ts-invariant.

There doesn't seem to be any existing tests for this functionality, but I'm happy to create some if necessary. EDIT: I found a place to add an unit test.

Feel free to merge, edit, or reject this pull request. Since the change is small enough, I figured it's easier to just create a PR rather than submit an issue for the feature request first.

@iiroj iiroj requested review from a team as code owners March 9, 2024 19:20
@apollo-cla
Copy link

@iiroj: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link

netlify bot commented Mar 9, 2024

👷 Deploy request for apollo-client-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c68daa9

Copy link

changeset-bot bot commented Mar 9, 2024

🦋 Changeset detected

Latest commit: c68daa9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@iiroj iiroj force-pushed the suppress-invariant-log-messages branch from 8a21ebb to f59279c Compare March 9, 2024 19:26
@iiroj iiroj force-pushed the suppress-invariant-log-messages branch from f59279c to c68daa9 Compare March 9, 2024 21:27
@phryneas
Copy link
Member

I think this should already be possible without code changes in Apollo Client:

import { setVerbosity } from "ts-invariant";

setVerbosity("silent");

Could you please try that before we further go down this route?

@iiroj
Copy link
Author

iiroj commented Mar 11, 2024

@phryneas thank you, I will test. If that works, maybe at least a documentation update would be nice.

@iiroj
Copy link
Author

iiroj commented Mar 12, 2024

@phryneas I can confirm that setting the verbosity of ts-invariant to 'silent' achieves the same thing! I will close this Pull Request but you're willing to accept it, I can also:

  1. Update the documentation for the errors to mention this
  2. Export silenceErrorMessages from @apollo/client/dev which just calls this setVerbosity.

@iiroj iiroj closed this Mar 12, 2024
@phryneas
Copy link
Member

I'd be happy to accept a PR that does 1. here - I don't think we need to ship additional code for this, but an edit to the documentation to highlight this would be very welcome!

@iiroj
Copy link
Author

iiroj commented Mar 12, 2024

Just to make sure: how about re-exporting setVerbosity from @apollo/client/dev? My ESLint ruleset doesn't like importing from packages that are not explicitly installed.

@phryneas
Copy link
Member

Yeah, I think that would be fine.

@iiroj iiroj changed the title fix: allow suppressing invariant log messages fix: re-export setVerbosity from ts-invariant Mar 13, 2024
@iiroj
Copy link
Author

iiroj commented Mar 13, 2024

Ping @phryneas I tried to re-open this PR but for some reason it is not possible... opened a new one at #11667

@iiroj iiroj changed the title fix: re-export setVerbosity from ts-invariant fix: allow suppressing invariant log messages Mar 13, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants