Skip to content
Open
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ npm install -g get-graphql-schema
Options:
--header, -h Add a custom header (ex. 'X-API-KEY=ABC123'), can be used multiple times
--json, -j Output in JSON format (based on introspection query)
--version, -v Print version of get-graphql-schema

--method Use method (GET,POST, PUT, DELETE)
--output Save schema to file
--allowInsecure, -k Ignore invalid and self-signed certificate checks.
```

## Help & Community [![Slack Status](https://slack.graph.cool/badge.svg)](https://slack.graph.cool)
Expand Down
8 changes: 7 additions & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Options:
--header, -h Add a custom header (ex. 'X-API-KEY=ABC123'), can be used multiple times
--json, -j Output in JSON format (based on introspection query)
--method Use method (GET,POST, PUT, DELETE)
--output Save schema to file.
--output Save schema to file
--allowInsecure, -k Ignore invalid and self-signed certificate checks.
`,
{
flags: {
Expand All @@ -34,6 +35,10 @@ Options:
output: {
type: 'string',
},
allowInsecure: {
type: 'boolean',
alias: 'k',
},
},
},
)
Expand Down Expand Up @@ -68,6 +73,7 @@ export async function main(cli: meow.Result): Promise<void> {
method: cli.flags.method,
headers,
json: cli.flags.json,
allowInsecure: cli.flags.allowInsecure,
})

if (schema.status === 'err') {
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetch from 'node-fetch'
import * as https from 'https';
import * as fs from 'fs'
import * as path from 'path'
import meow = require('meow')
Expand Down Expand Up @@ -40,6 +41,7 @@ interface Options {
method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
headers?: { [key: string]: string }
json?: boolean
allowInsecure: boolean
}

/**
Expand All @@ -56,7 +58,12 @@ export async function getRemoteSchema(
{ status: 'ok'; schema: string } | { status: 'err'; message: string }
> {
try {
const agent = new https.Agent({
rejectUnauthorized: !options.allowInsecure,
});

const { data, errors } = await fetch(endpoint, {
agent,
method: options.method,
headers: options.headers,
body: JSON.stringify({ query: introspectionQuery }),
Expand Down