Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [#1618] Fixes an issue when enums with a value of 0 fail to resolve when using a Federated Schema (https://github.com/apollographql/apollo-tooling/pull/1618)
- `apollo-language-server`
- Rename "Engine" to "Apollo Graph Manager" in ouput [#1705](https://github.com/apollographql/apollo-tooling/pull/1705)
- Add helpful messages for common errors when introspecting schemas [#1713](https://github.com/apollographql/apollo-tooling/pull/1713)
- `apollo-tools`
- <First `apollo-tools` related entry goes here>
- `vscode-apollo`
Expand Down
48 changes: 46 additions & 2 deletions packages/apollo-language-server/src/providers/schema/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
} from "graphql";
import { Agent as HTTPSAgent } from "https";
import { fetch } from "apollo-env";
import { RemoteServiceConfig } from "../../config";
import { RemoteServiceConfig, DefaultServiceConfig } from "../../config";
import { GraphQLSchemaProvider, SchemaChangeUnsubscribeHandler } from "./base";
import { Debug } from "../../utilities";
import { isString } from "util";

export class EndpointSchemaProvider implements GraphQLSchemaProvider {
private schema?: GraphQLSchema;
Expand All @@ -39,7 +40,50 @@ export class EndpointSchemaProvider implements GraphQLSchemaProvider {
query: parse(getIntrospectionQuery()),
context: { headers }
})
)) as ExecutionResult<IntrospectionQuery>;
).catch(e => {
// html response from introspection
if (isString(e.message) && e.message.includes("token <")) {
throw new Error(
"Apollo tried to introspect a running GraphQL service at " +
url +
"\nIt expected a JSON schema introspection result, but got an HTML response instead." +
"\nYou may need to add headers to your request or adjust your endpoint url.\n" +
"-----------------------------\n" +
"For more information, please refer to: https://bit.ly/2ByILPj \n\n" +
"The following error occurred:\n-----------------------------\n" +
e.message
);
}

// 404 encountered with the default url
if (
url === DefaultServiceConfig.endpoint.url &&
isString(e.message) &&
e.message.includes("ECONNREFUSED")
) {
throw new Error(
"Failed to connect to a running GraphQL endpoint at " +
url +
"\nThis may be because you didn't start your service.\n" +
"By default, when an endpoint, Graph Manager API key, or localSchemaFile isn't provided, Apollo tries to fetch a schema from " +
DefaultServiceConfig.endpoint.url +
"\n-----------------------------\n" +
"\nFor more information, please refer to: https://bit.ly/2ByILPj \n\n" +
"The following error occurred: \n" +
"-----------------------------\n" +
e.message
);
}
// 404 with a non-default url
if (isString(e.message) && e.message.includes("ECONNREFUSED")) {
throw new Error(
"Failed to connect to a running GraphQL endpoint at " +
url +
"\nThis may be because you didn't start your service or the endpoint URL is incorrect."
);
}
throw new Error(e);
})) as ExecutionResult<IntrospectionQuery>;

if (errors && errors.length) {
// XXX better error handling of GraphQL errors
Expand Down