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

graphql-schema-linter

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-schema-linter - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

4

CHANGELOG.md
# Changelog
## 0.0.10 (August 15th, 2017)
- Add ability to configure `graphql-schema-linter` via configuration files. [#26](https://github.com/cjoudrey/graphql-schema-linter/pull/26)
## 0.0.9 (August 10th, 2017)

@@ -4,0 +8,0 @@

2

lib/cli.js

@@ -11,3 +11,3 @@ #!/usr/bin/env node

console.error('');
console.error(err);
console.error(err.stack);
process.exit(2);

@@ -14,0 +14,0 @@ });

@@ -10,2 +10,12 @@ 'use strict';

var _fs = require('fs');
var _graphqlConfig = require('graphql-config');
var _graphqlConfig2 = _interopRequireDefault(_graphqlConfig);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _index = require('./rules/index.js');

@@ -23,8 +33,2 @@

var _graphqlConfig = require('graphql-config');
var _graphqlConfig2 = _interopRequireDefault(_graphqlConfig);
var _fs = require('fs');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -34,7 +38,24 @@

var cosmiconfig = require('cosmiconfig');
var Configuration = exports.Configuration = function () {
function Configuration(options, stdinFd) {
/*
options:
- configDirectory: path to begin searching for config files
- except: [string array] blacklist rules
- format: (required) `text` | `json`
- only: [string array] whitelist rules
- schemaFileName: [string] file to read schema from
- stdin: [boolean] pass schema via stdin?
*/
function Configuration() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var stdinFd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
_classCallCheck(this, Configuration);
this.options = options;
var defaultOptions = { format: 'text' };
var configOptions = loadOptionsFromConfig(options.configDirectory);
this.options = Object.assign({}, defaultOptions, configOptions, options);
this.stdinFd = stdinFd;

@@ -50,4 +71,4 @@ }

return getSchemaFromFileDescriptor(this.stdinFd);
} else if (this.options.args.length > 0) {
return getSchemaFromFile(this.options.args[0]);
} else if (this.options.schemaFileName) {
return getSchemaFromFile(this.options.schemaFileName);
} else {

@@ -76,14 +97,10 @@ // TODO: Get schema from .graphqlconfig file

var rules;
var rules = _index2.default;
if (this.options.only.length > 0) {
if (this.options.only && this.options.only.length > 0) {
rules = filterRules(this.options.only);
} else if (this.options.except && this.options.except.length > 0) {
rules = _index2.default.filter(function (rule) {
return _this.options.only.map(toUpperCamelCase).indexOf(rule.name) >= 0;
});
} else if (this.options.except.length > 0) {
rules = _index2.default.filter(function (rule) {
return _this.options.except.map(toUpperCamelCase).indexOf(rule.name) == -1;
});
} else {
rules = _index2.default;
}

@@ -98,2 +115,27 @@

function loadOptionsFromConfig(configDirectory) {
// If config path is not specified, look in root directory of project
// the first option to cosmiconfig.load can be absolute or relative
var searchPath = configDirectory || './';
var cosmic = cosmiconfig('graphql-schema-linter', {
cache: false,
sync: true
}).load(searchPath);
var options = {};
if (cosmic) {
// Map config.rules -> `only` param
if (cosmic.config.rules) {
options.only = cosmic.config.rules;
}
}
return options;
}
function filterRules(rules) {
return _index2.default.filter(function (rule) {
return rules.map(toUpperCamelCase).indexOf(rule.name) >= 0;
});
}
function getSchemaFromFileDescriptor(fd) {

@@ -100,0 +142,0 @@ var b = new Buffer(1024);

@@ -23,11 +23,5 @@ 'use strict';

function run(stdout, stdin, 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);
_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('-c, --config-directory <path>', 'path to begin searching for config files.').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 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
}, stdin.fd);
var configuration = new _configuration.Configuration(getOptionsFromCommander(_commander2.default), stdin.fd);

@@ -43,2 +37,28 @@ var schema = configuration.getSchema();

return errors.length > 0 ? 1 : 0;
}
function getOptionsFromCommander(commander) {
var options = { stdin: commander.stdin };
if (commander.configDirectory) {
options.configDirectory = commander.configDirectory;
}
if (commander.except) {
options.except = commander.except.split(',');
}
if (commander.format) {
options.format = commander.format;
}
if (commander.only) {
options.only = commander.only.split(',');
}
if (commander.args && commander.args.length) {
options.schemaFileName = commander.args[0];
}
return options;
}
{
"name": "graphql-schema-linter",
"version": "0.0.9",
"version": "0.0.10",
"description": "Command line tool and package to validate GraphQL schemas against a set of rules.",

@@ -40,2 +40,3 @@ "author": "Christian Joudrey",

"commander": "^2.11.0",
"cosmiconfig": "davidtheclark/cosmiconfig#3.0",
"figures": "^2.0.0",

@@ -42,0 +43,0 @@ "graphql": "^0.10.1",

@@ -62,2 +62,32 @@ # graphql-schema-linter [![Travis CI](https://travis-ci.org/cjoudrey/graphql-schema-linter.svg?branch=master)](https://travis-ci.org/cjoudrey/graphql-schema-linter) [![npm version](https://badge.fury.io/js/graphql-schema-linter.svg)](https://yarnpkg.com/en/package/graphql-schema-linter)

## Config
In addition to being able to specify rules on the command line, config can also be placed in the following locations:
### In `package.json`
```json
{
"graphql-schema-linter": {
"rules": ["enum-values-sorted-alphabetically"]
}
}
```
### In `.graphql-schema-linterrc`
```json
{
"rules": ["enum-values-sorted-alphabetically"]
}
```
### In `graphql-schema-linter.config.js`
```js
module.exports = {
rules: ['enum-values-sorted-alphabetically'],
};
```
## Built-in rules

@@ -64,0 +94,0 @@

Sorry, the diff of this file is not supported yet

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