Skip to content

Commit aa88d87

Browse files
trevor-scheerJames Baxley
authored andcommitted
Restore skipSSLValidation flag (#735)
This restores the skipSSLValidation flag so a schema introspection can be downloaded via http.
1 parent 4898efc commit aa88d87

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

packages/apollo-language-server/src/schema/providers/introspection.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import {
1010
IntrospectionQuery,
1111
parse
1212
} from "graphql";
13-
import { Agent, AgentOptions } from "https";
13+
import { Agent } from "http";
1414
import { fetch } from "apollo-env";
15-
import { URL } from "url";
16-
1715
import { RemoteServiceConfig } from "../../config";
1816
import { GraphQLSchemaProvider, SchemaChangeUnsubscribeHandler } from "./base";
1917

@@ -23,23 +21,11 @@ export class IntrospectionSchemaProvider implements GraphQLSchemaProvider {
2321
async resolveSchema() {
2422
if (this.schema) return this.schema;
2523
const { skipSSLValidation, url, headers } = this.config;
26-
let options: HttpLink.Options = { uri: url, fetch };
27-
28-
if (skipSSLValidation) {
29-
const urlObject = new URL(url);
30-
const host = urlObject.host;
31-
const port = +urlObject.port || 443;
32-
33-
const agentOptions: AgentOptions = {
34-
host: host,
35-
port: port,
36-
rejectUnauthorized: false
37-
};
38-
39-
const agent = new Agent(agentOptions);
40-
41-
options.fetchOptions = { agent: agent };
42-
}
24+
const options: HttpLink.Options = {
25+
uri: url,
26+
fetch,
27+
...(skipSSLValidation && { fetchOptions: { agent: new Agent() } })
28+
};
4329

4430
const { data, errors } = (await toPromise(
4531
linkExecute(createHttpLink(options), {

packages/apollo/src/Command.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface Flags {
3232
engine?: string;
3333
frontend?: string;
3434
tag?: string;
35+
skipSSLValidation?: boolean;
3536
}
3637

3738
const headersArrayToObject = (
@@ -130,7 +131,8 @@ export abstract class ProjectCommand extends Command {
130131
service: {
131132
endpoint: {
132133
url: flags.endpoint,
133-
headers: headersArrayToObject(flags.header)
134+
headers: headersArrayToObject(flags.header),
135+
...(flags.skipSSLValidation && { skipSSLValidation: true })
134136
}
135137
}
136138
});

packages/apollo/src/commands/service/download.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export default class ServiceDownload extends ProjectCommand {
1414
char: "t",
1515
description: "The published tag to check this service against",
1616
default: "current"
17+
}),
18+
skipSSLValidation: flags.boolean({
19+
char: "k",
20+
description: "Allow connections to an SSL site without certs"
1721
})
1822
};
1923

0 commit comments

Comments
 (0)