-
Notifications
You must be signed in to change notification settings - Fork 463
Add helpful message for invalid API key #1413
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| lastFetch: this.lastLoadDate | ||
| }; | ||
| } | ||
|
|
@@ -271,15 +272,19 @@ export class GraphQLClientProject extends GraphQLProject { | |
| await this.loadingHandler.handle( | ||
| `Loading Engine data for ${this.displayName}`, | ||
| (async () => { | ||
| const { | ||
| schemaTags, | ||
| fieldStats | ||
| } = await engineClient.loadSchemaTagsAndFieldStats(serviceID); | ||
| this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]); | ||
| this.fieldStats = fieldStats; | ||
| this.lastLoadDate = +new Date(); | ||
|
|
||
| this.generateDecorations(); | ||
| try { | ||
| const { | ||
| schemaTags, | ||
| fieldStats | ||
| } = await engineClient.loadSchemaTagsAndFieldStats(serviceID); | ||
| this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]); | ||
| this.fieldStats = fieldStats; | ||
| this.lastLoadDate = +new Date(); | ||
|
|
||
| this.generateDecorations(); | ||
| } catch (e) { | ||
| console.error(e); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| })() | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import gql from "graphql-tag"; | |
| import { GraphQLSchema, buildClientSchema } from "graphql"; | ||
| import { ApolloEngineClient, ClientIdentity } from "../../engine"; | ||
| import { ClientConfig, parseServiceSpecifier } from "../../config"; | ||
| import { getServiceFromKey } from "../../config/utils"; | ||
| import { | ||
| GraphQLSchemaProvider, | ||
| SchemaChangeUnsubscribeHandler, | ||
|
|
@@ -44,6 +45,15 @@ export class EngineSchemaProvider implements GraphQLSchemaProvider { | |
| } | ||
|
|
||
| const [id, tag = "current"] = parseServiceSpecifier(client.service); | ||
|
|
||
| // make sure the API key is valid for the service we're requesting a schema of. | ||
| const keyServiceName = getServiceFromKey(engine.apiKey); | ||
| if (id !== keyServiceName) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yesssss |
||
| throw new Error( | ||
| `API key service name (${keyServiceName}) does not match the service name in your config (${id}). Try changing the service name in your config to ${keyServiceName} or get a new key.` | ||
| ); | ||
| } | ||
|
|
||
| const { data, errors } = await this.client.execute<GetSchemaByTag>({ | ||
| query: SCHEMA_QUERY, | ||
| variables: { | ||
|
|
||
There was a problem hiding this comment.
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