graphql-doc-check
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -14,2 +14,8 @@ 'use strict'; | ||
var parser = function parser() { | ||
/** | ||
* Determines if a type should be ignored from parsing | ||
* | ||
* @param {Object} type Type to check | ||
* @return {Boolean} Should be ignored? | ||
*/ | ||
var typeShouldBeIgnored = function typeShouldBeIgnored(type) { | ||
@@ -38,2 +44,6 @@ var ignores = ['__Type', '__Field', '__InputValue', '__EnumValue', '__Directive']; | ||
if (item.isDeprecated && _lodash2.default.isEmpty(item.deprecationReason)) { | ||
missing.push('deprecationReason'); | ||
} | ||
return { name: item.name, missing: missing }; | ||
@@ -104,2 +114,14 @@ }; | ||
}).value(); | ||
}, | ||
/** | ||
* Parse a given schema | ||
* @param {Object} schema Schema to parse | ||
* @return {Object} Parsed schema | ||
*/ | ||
parse: function parse(schema) { | ||
schema.types = this.parseTypes(schema.types); | ||
return schema; | ||
} | ||
@@ -106,0 +128,0 @@ }; |
@@ -15,6 +15,2 @@ 'use strict'; | ||
var _parser = require('./parser'); | ||
var _parser2 = _interopRequireDefault(_parser); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -25,12 +21,24 @@ | ||
print: function print(schema) { | ||
/** | ||
* Renders a schema's results | ||
* | ||
* @param {Object} schema Schema to render | ||
* @return {String} Result output | ||
*/ | ||
print: function print(results) { | ||
this.missingTotal = 0; | ||
var types = _parser2.default.parseTypes(schema.types); | ||
var trees = this.renderTypes(types).map(function (type) { | ||
var typeTrees = this.renderTypes(results.types).map(function (type) { | ||
return _asciiTree2.default.generate(type); | ||
}).join('\n\n'); | ||
return this.renderHeading() + '\n\n' + trees; | ||
return this.renderHeading() + '\n\n' + typeTrees; | ||
}, | ||
/** | ||
* Renders the heading | ||
* | ||
* @return {String} Heading | ||
*/ | ||
renderHeading: function renderHeading() { | ||
@@ -46,2 +54,10 @@ switch (this.missingTotal) { | ||
}, | ||
/** | ||
* Render a list of types | ||
* | ||
* @param {Array} types Types to render | ||
* @return {Array} Rendered types | ||
*/ | ||
renderTypes: function renderTypes(types) { | ||
@@ -61,2 +77,10 @@ var _this = this; | ||
}, | ||
/** | ||
* Render a list of fields | ||
* | ||
* @param {Array} fields Fields to render | ||
* @return {String} Rendered fields | ||
*/ | ||
renderFields: function renderFields(fields) { | ||
@@ -68,3 +92,3 @@ var _this2 = this; | ||
var args = _this2.parseArgs(field.args); | ||
var args = _this2.renderArgs(field.args); | ||
if (args) { | ||
@@ -77,3 +101,11 @@ output += '\n' + args; | ||
}, | ||
parseArgs: function parseArgs(args) { | ||
/** | ||
* Render a list of arguments | ||
* | ||
* @param {Array} args Args to render | ||
* @return {String} Rendered args | ||
*/ | ||
renderArgs: function renderArgs(args) { | ||
var _this3 = this; | ||
@@ -85,2 +117,10 @@ | ||
}, | ||
/** | ||
* Renders a single result line: "name [prop1 | prop2]" | ||
* | ||
* @param {Object} ... Result to render | ||
* @return {String} Rendered result line | ||
*/ | ||
renderResultLine: function renderResultLine(_ref) { | ||
@@ -98,2 +138,10 @@ var name = _ref.name; | ||
}, | ||
/** | ||
* Render a missing list: "[prop1 | prop2]" | ||
* | ||
* @param {Array} missing Missing props | ||
* @return {String} Rendered missing props | ||
*/ | ||
renderMissingList: function renderMissingList(missing) { | ||
@@ -104,14 +152,2 @@ return '[' + missing.join(' | ') + ']'; | ||
exports.default = printer; | ||
// Missing 18 descriptions | ||
// Query [✗ desc | ✗ name] | ||
// person | ||
// id [✗ desc] | ||
// people [✗ desc | ✗ name] | ||
// Query [desc|name] | ||
// ├- person | ||
// │ ├- id [desc] | ||
// └- people [desc|name] | ||
exports.default = printer; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
var query = 'query {\n schema: __schema {\n types {\n kind\n name\n description\n fields {\n name\n description\n args {\n name\n description\n }\n }\n }\n }\n}'; | ||
var query = 'query {\n schema: __schema {\n types {\n kind\n name\n description\n fields {\n name\n description\n isDeprecated\n deprecationReason\n args {\n name\n description\n }\n }\n }\n }\n}'; | ||
@@ -19,17 +19,19 @@ exports.default = function (request) { | ||
var url = arguments.length <= 0 || arguments[0] === undefined ? 'http://localhost/graphql' : arguments[0]; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = { | ||
var requestOptions = { | ||
url: url, | ||
qs: { query: query }, | ||
headers: options.headers || {}, | ||
json: true | ||
}; | ||
return request(options).then(function (res) { | ||
return request(requestOptions).then(function (res) { | ||
return res.data.schema; | ||
}, function () { | ||
console.error('Unable to connect to ' + url + '.'); | ||
process.exit(); | ||
process.exit(1); | ||
}).catch(function () { | ||
console.log('GraphQL schema not found at ' + url + '.'); | ||
process.exit(); | ||
process.exit(1); | ||
}); | ||
@@ -36,0 +38,0 @@ } |
{ | ||
"name": "graphql-doc-check", | ||
"version": "0.1.1", | ||
"description": "Check for missing descriptions and field names in your GraphQL API", | ||
"version": "0.2.0", | ||
"description": "Check for missing documentation in your GraphQL Schema", | ||
"author": "Jordan Adams <hi@jordanadams.co.uk>", | ||
"license": "ISC", | ||
"main": "dist/index.js", | ||
"main": "dist/bin/graphql-doc-check.js", | ||
"bin": { | ||
"graphql-doc-check": "dist/index.js" | ||
"graphql-doc-check": "dist/bin/graphql-doc-check.js" | ||
}, | ||
@@ -22,3 +22,4 @@ "scripts": { | ||
"lodash": "^4.3.0", | ||
"request-promise": "^2.0.0" | ||
"request-promise": "^2.0.0", | ||
"yargs": "^4.1.0" | ||
}, | ||
@@ -31,2 +32,3 @@ "devDependencies": { | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.5.2", | ||
"expect": "^1.14.0", | ||
@@ -33,0 +35,0 @@ "isparta": "^4.0.0", |
@@ -6,6 +6,8 @@ GraphQL Documentation Check | ||
[![Dependency Status](https://david-dm.org/jordanadams/graphql-doc-check.svg)](https://david-dm.org/jordanadams/graphql-doc-check) | ||
[![npm](https://img.shields.io/npm/v/graphql-doc-check.svg)](https://www.npmjs.com/package/graphql-doc-check) | ||
[![Gitter](https://badges.gitter.im/JordanAdams/graphql-doc-check.svg)](https://gitter.im/JordanAdams/graphql-doc-check?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) | ||
Quickly find any missing documentation in your GraphQL API using introspection. Performs inspections remotely, without any need to access code. | ||
![Example screenshot](media/screenshot.png) | ||
![Example screenshot](https://raw.githubusercontent.com/JordanAdams/graphql-doc-check/master/media/screenshot.png) | ||
@@ -27,2 +29,6 @@ ## Installation | ||
For more info, consult the help: | ||
$ graphql-doc-check -h | ||
Results are shown in a tree structure with fields missing documentation in red. | ||
@@ -29,0 +35,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74685
12
286
49
5
12
+ Addedyargs@^4.1.0
+ Addedcamelcase@3.0.0(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedos-locale@1.4.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich-module@1.0.0(transitive)
+ Addedwindow-size@0.2.0(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyargs@4.8.1(transitive)
+ Addedyargs-parser@2.4.1(transitive)