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 helpful message for invalid API key #1413

Merged
merged 4 commits into from
Jul 19, 2019
Merged

Conversation

JakeDawkins
Copy link
Contributor

@JakeDawkins JakeDawkins commented Jul 18, 2019

Right now, there's no error being printed when schema lookup fails.

This PR aims to fix that, and add at least a safeguard for people using incorrect API keys. This can be partially checked on the client by checking the config.service.name against the identifier in the API key.

See the comments in the file changes for more explanation.

For the future, we really should standardize our error strategy to make sure they're being printed prettily in the editor. Right now, we're getting some pretty ugly stack traces.

TODO:

  • Update CHANGELOG.md* with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

*Make sure changelog entries note which project(s) has been affected. See older entries for examples on what this looks like.

@@ -169,7 +169,8 @@ export class GraphQLClientProject extends GraphQLProject {
total: totalTypes
},
tag: this.config.tag,
loaded: this.serviceID ? true : false,
loaded:
this.serviceID && (this.schema || this.serviceSchema) ? true : false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This checks to make sure the project actually has a schema. Previously, this would pass if there are 0 types on both the client and service, and it would show users in the console that everything was fine. This is not true :)

Copy link
Member

Choose a reason for hiding this comment

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

Nit: Boolean(this.serviceID && (this.schema || this.serviceSchema))


this.generateDecorations();
} catch (e) {
console.error(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wrapped this in a try/catch so we're not letting any unhandled rejections through

Copy link
Member

Choose a reason for hiding this comment

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

Just making a note that I believe that errors here are meant to bubble up to the LoadingHandler. They're try/catch in the handler so it can communicate them to the extension. This may be a better UX or we may need to improve the messages we send across the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has to be here or else I get an unhandled rejection error 😬 I'd love to know how to properly fix this though

if (!(data && data.service)) {
throw new Error();
if (!(data && data.service) || errors) {
throw new Error(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we can't find a service, we should at least give a recommendation for why

@@ -169,7 +169,8 @@ export class GraphQLClientProject extends GraphQLProject {
total: totalTypes
},
tag: this.config.tag,
loaded: this.serviceID ? true : false,
loaded:
this.serviceID && (this.schema || this.serviceSchema) ? true : false,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Boolean(this.serviceID && (this.schema || this.serviceSchema))


this.generateDecorations();
} catch (e) {
console.error(e);
Copy link
Member

Choose a reason for hiding this comment

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

Just making a note that I believe that errors here are meant to bubble up to the LoadingHandler. They're try/catch in the handler so it can communicate them to the extension. This may be a better UX or we may need to improve the messages we send across the connection.


// make sure the API key is valid for the service we're requesting a schema of.
const keyServiceName = getServiceFromKey(engine.apiKey);
if (id !== keyServiceName) {
Copy link
Member

Choose a reason for hiding this comment

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

Yesssss

@JakeDawkins JakeDawkins marked this pull request as ready for review July 18, 2019 19:50
- Fixed unneeded ternary
- Added ApolloConfig as an `apollo` type export
@JakeDawkins JakeDawkins merged commit 5baa5e3 into master Jul 19, 2019
@JakeDawkins JakeDawkins deleted the jake/api-key-error branch July 19, 2019 16:13
essaji pushed a commit to essaji/apollo-tooling that referenced this pull request Aug 25, 2019
* Add check for api-key/serviceName match
* Added ApolloConfig as an `apollo` type export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants