-
Notifications
You must be signed in to change notification settings - Fork 463
Support for self-signed certificates #565
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 1 commit
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ export interface SchemaDependency { | |
| engineKey?: string; | ||
| extends?: string; | ||
| clientSide?: boolean; | ||
| skipsSSLValidation?: boolean; | ||
|
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. I think this should probably be part of
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. I think this is a great suggestion and actually I thought about implementing this way on the first place. 👍 |
||
| } | ||
|
|
||
| export interface DocumentSet { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,15 @@ | ||
| import { extractDocumentFromJavascript } from "apollo-codegen-core/lib/loading"; | ||
| import { fs } from "apollo-codegen-core/lib/localfs"; | ||
| import * as path from "path"; | ||
| import fetch from "node-fetch"; | ||
| import gql from "graphql-tag"; | ||
| import { | ||
| buildSchema, | ||
| introspectionQuery, | ||
| GraphQLSchema, | ||
| Source, | ||
| buildClientSchema | ||
| } from "graphql"; | ||
| import { execute, toPromise } from "apollo-link"; | ||
| import { createHttpLink } from "apollo-link-http"; | ||
|
|
||
| import { extractDocumentFromJavascript } from "apollo-codegen-core/lib/loading"; | ||
| import { createHttpLink, HttpLink } from "apollo-link-http"; | ||
| import { buildClientSchema, buildSchema, GraphQLSchema, introspectionQuery, Source } from "graphql"; | ||
| import gql from "graphql-tag"; | ||
| import { Agent, AgentOptions } from 'https'; | ||
| import fetch from "node-fetch"; | ||
| import * as path from "path"; | ||
| import { URL } from 'url'; | ||
| import { EndpointConfig } from "./config"; | ||
| import { getIdFromKey, engineLink } from "./engine"; | ||
| import { engineLink, getIdFromKey } from "./engine"; | ||
| import { SCHEMA_QUERY } from "./operations/schema"; | ||
|
|
||
| const introspection = gql(introspectionQuery); | ||
|
|
@@ -56,15 +51,35 @@ export async function fromFile( | |
|
|
||
| export const fetchSchema = async ( | ||
| { url, headers }: EndpointConfig, | ||
| projectFolder?: string | ||
| projectFolder?: string, | ||
| insecureEnabled?: boolean | ||
| ): Promise<GraphQLSchema | undefined> => { | ||
| if (!url) throw new Error("No endpoint provided when fetching schema"); | ||
| const filePath = projectFolder ? path.resolve(projectFolder, url) : url; | ||
| if (fs.existsSync(filePath)) return fromFile(filePath); | ||
|
|
||
| const insecureOptionActive = insecureEnabled ? insecureEnabled : false; | ||
|
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. I think we can avoid an extra variable here by using a default parameter value (
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 discovered that checking a ( |
||
|
|
||
| var options: HttpLink.Options = { uri: url, fetch } | ||
|
|
||
| if (insecureOptionActive) { | ||
| const host = new URL(url).host | ||
|
|
||
| const agentOptions: AgentOptions = { | ||
| host: host, | ||
| port: 443, | ||
| rejectUnauthorized: false | ||
| }; | ||
|
|
||
| const agent = new Agent(agentOptions); | ||
|
|
||
| options.fetchOptions = { agent: agent } | ||
| } | ||
|
|
||
| return toPromise( | ||
| // XXX node-fetch isn't compatiable typescript wise here? | ||
| execute(createHttpLink({ uri: url, fetch } as any), { | ||
|
|
||
| // XXX node-fetch isn't compatible typescript wise here? | ||
| execute(createHttpLink(options), { | ||
| query: introspection, | ||
| context: { headers } | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ export async function loadSchema( | |
|
|
||
| if (dependency.endpoint && dependency.endpoint.url) { | ||
| try { | ||
| return await fetchSchema(dependency.endpoint, config.projectFolder); | ||
| return await fetchSchema(dependency.endpoint, config.projectFolder, dependency.skipsSSLValidation); | ||
|
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. If we put
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. Done |
||
| } catch {} | ||
| } | ||
|
|
||
|
|
||
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.
Wondering about the naming, because it's a bit confusing to have
insecure,skipsSSLValidation, andrejectUnauthorizedreferring to the same option.skipSSLValidationseems the most descriptive (I prefer skip vs. skips, but that's no biggie). I understand wanting to followcurlin usinginsecure, but consistency between command flag and config is more important here I think.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.
I agree on this that giving a more self-explanatory name is more important than keeping old names. So I decided to change this (also to skip instead of skips). Thanks for the feedback