Skip to content

Commit

Permalink
Replace stray console.debug with invariant.log.
Browse files Browse the repository at this point in the history
Since this message is promotional, I did not feel comfortable using
invariant.warn, but our default log level of "warn" would have hidden the
message unless setLogVerbosity("log") was called.

Since this is the only use of invariant.log in the codebase, I believe
it's acceptable to lower the default verbosity level to "log" to allow
this particular message to be displayed (otherwise, invariant.log messages
are effectively useless).

Fixes #7447 and #7453, since React Native polyfills the console object
without providing a console.debug method.
  • Loading branch information
benjamn committed Dec 10, 2020
1 parent dc715e0 commit 8478056
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
27 changes: 8 additions & 19 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,15 @@ export class ApolloClient<TCacheShape> implements DataProxy {
if (
typeof window !== 'undefined' &&
window.document &&
window.top === window.self
window.top === window.self &&
!(window as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__ &&
window?.navigator?.userAgent?.indexOf('Chrome') > -1
) {
// First check if devtools is not installed
if (
typeof (window as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined'
) {
// Only for Chrome
if (
window.navigator &&
window.navigator.userAgent &&
window.navigator.userAgent.indexOf('Chrome') > -1
) {
// tslint:disable-next-line
console.debug(
'Download the Apollo DevTools ' +
'for a better development experience: ' +
'https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm',
);
}
}
invariant.log(
'Download the Apollo DevTools ' +
'for a better development experience: ' +
'https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm',
);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ export {

// The verbosity of invariant.{log,warn,error} can be controlled globally
// (for anyone using the same ts-invariant package) by passing "log",
// "warn", "error", or "silent" to setVerbosity. By default, Apollo Client
// displays warnings and errors, but hides invariant.log statements. Note
// that all invariant.* logging is hidden in production.
// "warn", "error", or "silent" to setVerbosity ("log" is the default).
// Note that all invariant.* logging is hidden in production.
import { setVerbosity } from "ts-invariant";
export { setVerbosity as setLogVerbosity }
setVerbosity("warn");
setVerbosity("log");

// Note that importing `gql` by itself, then destructuring
// additional properties separately before exporting, is intentional.
Expand Down

0 comments on commit 8478056

Please sign in to comment.