Skip to content

Commit

Permalink
Add command line argument to set introspection url (#25)
Browse files Browse the repository at this point in the history
* Add ability to feed url into command line argument and override value in spec

* Change command line variable to be more specific

* "Pin dep to 6.2 since 7.0 has breaking changes"

* update package.lock

* Update yarn.lock

Co-authored-by: Oshin Karamian <oshin@lola.com>
  • Loading branch information
OshinKaramian and Oshin Karamian committed Mar 16, 2021
1 parent b16c5b6 commit a4841fd
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ $ dociql -h
-f, --target-file <file> the target build HTML file (default: index.html)
-a, --app-dir <dir> the application source directory (default: app)
-l, --logo-file <file> specify a custom logo file (default: null)
-1, --one-file embed all resources (CSS and JS) into the same file (default: false)
-u, --introspection-url <url> specify a custom url to use for introspection (default: none)
-c, --config-file <file> specify a custom configuration file (default: app/lib/config.js)
```

Expand Down
7 changes: 4 additions & 3 deletions app/dociql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ const fs = require("fs")
const fetchSchema = require("./fetch-schema")
const composePaths = require("./compose-paths")

module.exports = function(specPath, headers) {
module.exports = function(specPath, headers, introspectionUrl) {
// read spec file content
const fileContent = fs.readFileSync(specPath, "utf8")
// deserialise
const spec = yaml.safeLoad(fileContent)
// fetch graphQL Schema
const graphUrl = spec.introspection
// fetch graphQL Schema, if given an introspection url use that over the value in
// the spec
const graphUrl = introspectionUrl ? introspectionUrl : spec.introspection
const {graphQLSchema, jsonSchema} = fetchSchema(graphUrl, headers)

// parse URL
Expand Down
1 change: 1 addition & 0 deletions bin/dociql.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ program.version(package.version)
.option('-l, --logo-file <file>', 'specify a custom logo file (default: null)', String, null)
.option('-c, --config-file <file>', 'specify a custom configuration file (default: app/lib/config.js)')
.option('-H, --header <header>', 'specify a custom auth token for the header (default: none)')
.option('-u, --introspection-url <url>', 'specify a custom url to use for introspection (default: none)')
.option('-q, --quiet', 'Silence the output from the generator (default: false)')
// .option('-f, --spec-file <file>', 'the input OpenAPI/Swagger spec file (default: test/fixtures/petstore.json)', String, 'test/fixtures/petstore.json')
.parse(process.argv)
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = function (options) {

function loadData() {
var specPath = path.resolve(opts.specFile)
var specData = require(path.resolve(opts.appDir + '/dociql/index'))(specPath, opts.header)
var specData = require(path.resolve(opts.appDir + '/dociql/index'))(specPath, opts.header, opts.introspectionUrl)
return require(path.resolve(opts.appDir + '/lib/preprocessor'))(options, specData)
}

Expand Down
Loading

0 comments on commit a4841fd

Please sign in to comment.