Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-doc-check

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-doc-check - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

CHANGELOG.md

22

dist/parser.js

@@ -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 @@ };

82

dist/printer.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc