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

add devtools suggestion to Apollo Client #1466

Merged
merged 1 commit into from
Mar 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ import {
version,
} from './version';



/**
* Suggest installing the devtools for developers who are using Apollo Client
*/
if (process.env.NODE_ENV !== 'production') {
if ( typeof window !== 'undefined' && window.document && window.top === window.self) {

// First check if devtools is not installed
if (typeof (window as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
// Only for Chrome
if (navigator.userAgent.indexOf('Chrome') > -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually a reliable way to detect chrome? Does anyone impersonate this string out of browsers we care about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think it's good enough. I don't think other clients impersonating Chrome matters in this case, because the main thing we want to do here is avoid printing it for innocent IE and Firefox users.

// 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');
}
}
}
}


/**
* This type defines a "selector" function that receives state from the Redux store
* and returns the part of it that is managed by ApolloClient
Expand Down