graphql-schema-linter
Advanced tools
Comparing version 0.0.3 to 0.0.4
# Changelog | ||
## 0.0.4 (August 4th, 2017) | ||
- Added `--only` and `--except` to control what rules get used to validate the schema. | ||
- Added `--help` and usage. | ||
- Added `--version` to obtain the version of `graphql-schema-linter`. | ||
## 0.0.3 (August 3rd, 2017) | ||
@@ -4,0 +10,0 @@ |
@@ -6,2 +6,4 @@ #!/usr/bin/env node | ||
(0, _runner.run)(process.argv.slice(2)); | ||
var exitCode = (0, _runner.run)(process.stdout, process.argv); | ||
process.exit(exitCode); |
@@ -11,5 +11,5 @@ "use strict"; | ||
var _class = function () { | ||
function _class(options) { | ||
_classCallCheck(this, _class); | ||
var JSONFormatter = function () { | ||
function JSONFormatter(configuration) { | ||
_classCallCheck(this, JSONFormatter); | ||
@@ -19,3 +19,3 @@ this.errors = []; | ||
_createClass(_class, [{ | ||
_createClass(JSONFormatter, [{ | ||
key: "start", | ||
@@ -38,5 +38,5 @@ value: function start() {} | ||
return _class; | ||
return JSONFormatter; | ||
}(); | ||
exports.default = _class; | ||
exports.JSONFormatter = JSONFormatter; |
@@ -11,5 +11,5 @@ 'use strict'; | ||
var _class = function () { | ||
function _class(options) { | ||
_classCallCheck(this, _class); | ||
var TextFormatter = function () { | ||
function TextFormatter(configuration) { | ||
_classCallCheck(this, TextFormatter); | ||
@@ -19,3 +19,3 @@ this.errors = ''; | ||
_createClass(_class, [{ | ||
_createClass(TextFormatter, [{ | ||
key: 'start', | ||
@@ -37,5 +37,5 @@ value: function start() {} | ||
return _class; | ||
return TextFormatter; | ||
}(); | ||
exports.default = _class; | ||
exports.TextFormatter = TextFormatter; |
@@ -5,2 +5,3 @@ 'use strict'; | ||
module.exports.rules = require('./rules/index.js'); | ||
module.exports.validator = require('./validator.js'); | ||
module.exports.validator = require('./validator.js'); | ||
module.exports.configuration = require('./configuration.js'); |
@@ -6,4 +6,9 @@ 'use strict'; | ||
}); | ||
exports.DeprecationsHaveAReason = DeprecationsHaveAReason; | ||
exports.default = function (context) { | ||
var _buildASTSchema = require('graphql/utilities/buildASTSchema'); | ||
var _error = require('graphql/error'); | ||
function DeprecationsHaveAReason(context) { | ||
return { | ||
@@ -33,8 +38,2 @@ FieldDefinition: function FieldDefinition(node, key, parent, path, ancestors) { | ||
var _buildASTSchema = require('graphql/utilities/buildASTSchema'); | ||
var _error = require('graphql/error'); | ||
; | ||
function isDeprecatedWithoutReason(node) { | ||
@@ -41,0 +40,0 @@ var deprecatedDirective = node.directives.find(function (directive) { |
@@ -6,4 +6,9 @@ 'use strict'; | ||
}); | ||
exports.FieldsHaveDescriptions = FieldsHaveDescriptions; | ||
exports.default = function (context) { | ||
var _buildASTSchema = require('graphql/utilities/buildASTSchema'); | ||
var _error = require('graphql/error'); | ||
function FieldsHaveDescriptions(context) { | ||
return { | ||
@@ -21,8 +26,2 @@ FieldDefinition: function FieldDefinition(node, key, parent, path, ancestors) { | ||
}; | ||
}; | ||
var _buildASTSchema = require('graphql/utilities/buildASTSchema'); | ||
var _error = require('graphql/error'); | ||
; | ||
}; |
@@ -5,14 +5,8 @@ 'use strict'; | ||
var _fields_have_descriptions2 = _interopRequireDefault(_fields_have_descriptions); | ||
var _deprecations_have_a_reason = require('./deprecations_have_a_reason.js'); | ||
var _deprecations_have_a_reason2 = _interopRequireDefault(_deprecations_have_a_reason); | ||
var _types_have_descriptions = require('./types_have_descriptions.js'); | ||
var _types_have_descriptions2 = _interopRequireDefault(_types_have_descriptions); | ||
var _types_are_capitalized = require('./types_are_capitalized.js'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
module.exports = [_fields_have_descriptions2.default, _deprecations_have_a_reason2.default, _types_have_descriptions2.default]; | ||
module.exports = [_fields_have_descriptions.FieldsHaveDescriptions, _deprecations_have_a_reason.DeprecationsHaveAReason, _types_have_descriptions.TypesHaveDescriptions, _types_are_capitalized.TypesAreCapitalized]; |
@@ -6,4 +6,7 @@ 'use strict'; | ||
}); | ||
exports.TypesAreCapitalized = TypesAreCapitalized; | ||
exports.default = function (context) { | ||
var _error = require('graphql/error'); | ||
function TypesAreCapitalized(context) { | ||
return { | ||
@@ -23,4 +26,2 @@ ObjectTypeDefinition: function ObjectTypeDefinition(node) { | ||
}; | ||
}; | ||
var _error = require('graphql/error'); | ||
} |
@@ -6,4 +6,9 @@ 'use strict'; | ||
}); | ||
exports.TypesHaveDescriptions = TypesHaveDescriptions; | ||
exports.default = function (context) { | ||
var _buildASTSchema = require('graphql/utilities/buildASTSchema'); | ||
var _error = require('graphql/error'); | ||
function TypesHaveDescriptions(context) { | ||
return { | ||
@@ -29,8 +34,2 @@ InterfaceTypeDefinition: function InterfaceTypeDefinition(node) { | ||
}; | ||
}; | ||
var _buildASTSchema = require('graphql/utilities/buildASTSchema'); | ||
var _error = require('graphql/error'); | ||
; | ||
}; |
@@ -8,4 +8,2 @@ 'use strict'; | ||
var _fs = require('fs'); | ||
var _validator = require('./validator.js'); | ||
@@ -15,32 +13,29 @@ | ||
var _graphqlConfig = require('graphql-config'); | ||
var _package = require('../package.json'); | ||
var _graphqlConfig2 = _interopRequireDefault(_graphqlConfig); | ||
var _commander = require('commander'); | ||
var _json_formatter = require('./formatters/json_formatter.js'); | ||
var _commander2 = _interopRequireDefault(_commander); | ||
var _json_formatter2 = _interopRequireDefault(_json_formatter); | ||
var _configuration = require('./configuration.js'); | ||
var _text_formatter = require('./formatters/text_formatter.js'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _text_formatter2 = _interopRequireDefault(_text_formatter); | ||
function run(stdout, argv) { | ||
_commander2.default.usage('[options] [schema.graphql]').option('-o, --only <rules>', 'only the rules specified will be used to validate the schema. Example: FieldsHaveDescriptions,TypesHaveDescriptions').option('-e, --except <rules>', 'all rules except the ones specified will be used to validate the schema. Example: FieldsHaveDescriptions,TypesHaveDescriptions').option('-f, --format <format>', 'choose the output format of the report. Possible values: json, text').option('-s, --stdin', 'schema definition will be read from STDIN instead of specified file.').version(_package.version, '--version').parse(argv); | ||
var _minimist = require('minimist'); | ||
var configuration = new _configuration.Configuration({ | ||
format: _commander2.default.format && _commander2.default.format.toLowerCase() || 'text', | ||
stdin: _commander2.default.stdin, | ||
only: _commander2.default.only && _commander2.default.only.split(',') || [], | ||
except: _commander2.default.except && _commander2.default.except.split(',') || [], | ||
args: _commander2.default.args | ||
}); | ||
var _minimist2 = _interopRequireDefault(_minimist); | ||
var schema = configuration.getSchema(); | ||
var formatter = configuration.getFormatter(); | ||
var rules = configuration.getRules(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var errors = (0, _validator.validateSchemaDefinition)(schema, rules); | ||
function run(argv) { | ||
var options = (0, _minimist2.default)(argv, { | ||
string: ["format"], | ||
boolean: ["stdin"], | ||
default: { format: "text" } | ||
}); | ||
var schema = getSchema(options); | ||
var formatter = getFormatter(options); | ||
// TODO: Add a way to configure rules | ||
var errors = (0, _validator.validateSchemaDefinition)(schema, _index.rules); | ||
formatter.start(); | ||
@@ -50,44 +45,5 @@ errors.map(function (error) { | ||
}); | ||
var output = formatter.output(); | ||
process.stdout.write(output); | ||
stdout.write(formatter.output()); | ||
process.exit(errors.length > 0 ? 1 : 0); | ||
} | ||
function getSchema(options) { | ||
if (options.stdin) { | ||
return getSchemaFromStdin(); | ||
} else if (options._.length > 0) { | ||
return getSchemaFromFile(options._[0]); | ||
} else { | ||
// TODO: Get schema from .graphqlconfig file | ||
} | ||
} | ||
function getSchemaFromStdin() { | ||
var b = new Buffer(1024); | ||
var data = ''; | ||
while (true) { | ||
var n = (0, _fs.readSync)(process.stdin.fd, b, 0, b.length); | ||
if (!n) { | ||
break; | ||
} | ||
data += b.toString('utf8', 0, n); | ||
} | ||
return data; | ||
} | ||
function getSchemaFromFile(path) { | ||
return (0, _fs.readFileSync)(path).toString('utf8'); | ||
} | ||
function getFormatter(options) { | ||
switch (options.format) { | ||
case 'json': | ||
return new _json_formatter2.default(options); | ||
case 'text': | ||
return new _text_formatter2.default(options); | ||
} | ||
return errors.length > 0 ? 1 : 0; | ||
} |
{ | ||
"name": "graphql-schema-linter", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Command line tool and package to validate GraphQL schemas against a set of rules.", | ||
@@ -35,5 +35,5 @@ "author": "Christian Joudrey", | ||
"dependencies": { | ||
"commander": "^2.11.0", | ||
"graphql": "^0.10.1", | ||
"graphql-config": "^1.0.0", | ||
"minimist": "^1.2.0" | ||
"graphql-config": "^1.0.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "bin": { |
@@ -1,2 +0,2 @@ | ||
# graphql-schema-linter | ||
# graphql-schema-linter [![Travis CI](https://travis-ci.org/cjoudrey/graphql-schema-linter.svg?branch=master)](https://travis-ci.org/cjoudrey/graphql-schema-linter) | ||
@@ -7,4 +7,2 @@ This package provides a command line tool to validate GraphQL schema definitions against a set of rules. | ||
_This is still work in progress._ | ||
## Install | ||
@@ -18,3 +16,3 @@ | ||
NPM: | ||
npm: | ||
@@ -30,15 +28,54 @@ ``` | ||
Options: | ||
--format | ||
-o, --only <rules> | ||
Choose the output format of the report. | ||
only the rules specified will be used to validate the schema | ||
Possible values: json, text | ||
example: --only FieldsHaveDescriptions,TypesHaveDescriptions | ||
--stdin | ||
-e, --except <rules> | ||
Schema definition will be read from STDIN instead of specified file. | ||
all rules except the ones specified will be used to validate the schema | ||
example: --except FieldsHaveDescriptions,TypesHaveDescriptions | ||
-f, --format <format> | ||
choose the output format of the report | ||
possible values: json, text | ||
-s, --stdin | ||
schema definition will be read from STDIN instead of specified file | ||
--version | ||
output the version number | ||
-h, --help | ||
output usage information | ||
``` | ||
## Built-in rules | ||
### `DeprecationsHaveAReason` | ||
This rule will validate that all deprecations have a reason. | ||
### `FieldsHaveDescriptions` | ||
This rule will validate that all fields have a description. | ||
### `TypesAreCapitalized` | ||
This rule will validate that interface types and object types have capitalized names. | ||
### `TypesHaveDescriptions` | ||
This will will validate that interface types and object types have descriptions. | ||
## Output formatters | ||
@@ -48,3 +85,3 @@ | ||
The following formatters are currently available: | ||
The following formatters are currently available: `text`, `json`. | ||
@@ -86,19 +123,1 @@ ### `TextFormatter` (default) | ||
``` | ||
## Built-in rules | ||
### `DeprecationsHaveAReason` | ||
This rule will validate that all deprecations have a reason. | ||
### `FieldsHaveDescriptions` | ||
This rule will validate that all fields have a description. | ||
### `TypesAreCapitalized` | ||
This rule will validate that interface types and object types have capitalized names. | ||
### `TypesHaveDescriptions` | ||
This will will validate that interface types and object types have descriptions. |
Sorry, the diff of this file is not supported yet
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
112190
23
310
119
+ Addedcommander@^2.11.0
+ Addedcommander@2.20.3(transitive)
- Removedminimist@^1.2.0
- Removedminimist@1.2.8(transitive)