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.5.0 to 1.0.0

lib/find_schema_nodes.js

14

CHANGELOG.md

@@ -11,2 +11,14 @@ # Changelog

## 1.0.0 (September 6th, 2020)
`graphql-schema-linter` has been in development since August 2017. During that time, 18 people have contributed 131 pull requests that make up the tool that we have today. :tada:
I believe the tool is now stable and can follow semantic versioning.
On that note, the addition or modification of existing rules will be considered a breaking change and thus will require bumping the MAJOR version of the library. By doing this, users of `graphql-schema-linter` won't get caught off guard by those changes.
### New features
- Add support for enabling / disabling rules for parts of the GraphQL schema using the `--ignore` option. This works functionally the same way as inline rule overrides, but is meant to be used when adding comments to the GraphQL schema is not possible. [#240](https://github.com/cjoudrey/graphql-schema-linter) (Thanks @id-ilych)
## 0.5.0 (July 4th, 2020)

@@ -16,3 +28,3 @@

- Add support for enabling / disabling rules for parts of the GraphQL schema using an inline rule override. See section in README.md for usage information. [#237](https://github.com/cjoudrey/graphql-schema-linter/pull/237) (Thanks @mshwery)
- Add support for enabling / disabling rules for parts of the GraphQL schema using an inline rule override. See [usage information in README.md](https://github.com/cjoudrey/graphql-schema-linter#inline-rule-overrides). [#237](https://github.com/cjoudrey/graphql-schema-linter/pull/237) (Thanks @mshwery)

@@ -19,0 +31,0 @@ ## 0.4.0 (May 5th, 2020)

@@ -25,2 +25,3 @@ "use strict";

- rules: [string array] whitelist rules
- ignore: [string to string array object] ignore list for rules. Example: {"fields-have-descriptions": ["Obvious", "Query.obvious", "Query.something.obvious"]}
- customRulePaths: [string array] path to additional custom rules to be loaded

@@ -35,3 +36,4 @@ - commentDescriptions: [boolean] use old way of defining descriptions in GraphQL SDL

commentDescriptions: false,
oldImplementsSyntax: false
oldImplementsSyntax: false,
ignore: {}
};

@@ -130,2 +132,6 @@ this.schema = schema;

getIgnoreList() {
return this.options.ignore;
}
validate() {

@@ -132,0 +138,0 @@ const issues = [];

@@ -35,2 +35,3 @@ "use strict";

rules: cosmic.config.rules,
ignore: cosmic.config.ignore,
customRulePaths: customRulePaths || [],

@@ -37,0 +38,0 @@ schemaPaths: schemaPaths

@@ -27,3 +27,3 @@ "use strict";

async function run(stdout, stdin, stderr, argv) {
const commander = new _commander.Command().usage('[options] [schema.graphql ...]').option('-r, --rules <rules>', 'only the rules specified will be used to validate the schema. Example: fields-have-descriptions,types-have-descriptions').option('-f, --format <format>', 'choose the output format of the report. Possible values: json, text, compact').option('-s, --stdin', 'schema definition will be read from STDIN instead of specified file.').option('-c, --config-directory <path>', 'path to begin searching for config files.').option('-p, --custom-rule-paths <paths>', 'path to additional custom rules to be loaded. Example: rules/*.js').option('--comment-descriptions', 'use old way of defining descriptions in GraphQL SDL').option('--old-implements-syntax', 'use old way of defining implemented interfaces in GraphQL SDL') // DEPRECATED - This code should be removed in v1.0.0.
const commander = new _commander.Command().usage('[options] [schema.graphql ...]').option('-r, --rules <rules>', 'only the rules specified will be used to validate the schema. Example: fields-have-descriptions,types-have-descriptions').option('-i, --ignore <ignore list>', "ignore errors for specific schema members, example: {'fields-have-descriptions':['Obvious','Query.obvious','Query.something.obvious']}").option('-f, --format <format>', 'choose the output format of the report. Possible values: json, text, compact').option('-s, --stdin', 'schema definition will be read from STDIN instead of specified file.').option('-c, --config-directory <path>', 'path to begin searching for config files.').option('-p, --custom-rule-paths <paths>', 'path to additional custom rules to be loaded. Example: rules/*.js').option('--comment-descriptions', 'use old way of defining descriptions in GraphQL SDL').option('--old-implements-syntax', 'use old way of defining implemented interfaces in GraphQL SDL') // DEPRECATED - This code should be removed in v1.0.0.
.option('-o, --only <rules>', 'This option is DEPRECATED. Use `--rules` instead.') // DEPRECATED - This code should be removed in v1.0.0.

@@ -111,2 +111,6 @@ .option('-e, --except <rules>', 'This option is DEPRECATED. Use `--rules` instead.').version(_package.version, '--version').parse(argv);

if (commander.ignore) {
options.ignore = JSON.parse(commander.ignore);
}
if (commander.customRulePaths) {

@@ -113,0 +117,0 @@ options.customRulePaths = commander.customRulePaths.split(',');

@@ -24,2 +24,4 @@ "use strict";

var _find_schema_nodes = require("./find_schema_nodes");
function validateSchemaDefinition(inputSchema, rules, configuration) {

@@ -71,4 +73,4 @@ let ast;

const sortedErrors = sortErrors(errors);
const inlineConfigs = (0, _inline_configuration.extractInlineConfigs)(ast);
const filteredErrors = applyInlineConfig(sortedErrors, inputSchema.sourceMap, inlineConfigs);
const errorFilters = [inlineConfigErrorFilter(ast, inputSchema), ignoreListErrorFilter(schema, configuration)];
const filteredErrors = sortedErrors.filter(error => errorFilters.every(filter => filter(error)));
return filteredErrors;

@@ -93,8 +95,11 @@ }

function applyInlineConfig(errors, schemaSourceMap, inlineConfigs) {
function inlineConfigErrorFilter(ast, inputSchema) {
const inlineConfigs = (0, _inline_configuration.extractInlineConfigs)(ast);
if (inlineConfigs.length === 0) {
return errors;
return () => true;
}
return errors.filter(error => {
const schemaSourceMap = inputSchema.sourceMap;
return error => {
let shouldApplyRule = true;

@@ -134,3 +139,22 @@ const errorLine = error.locations[0].line;

return shouldApplyRule;
});
};
}
function ignoreListErrorFilter(schema, configuration) {
const ignoreList = configuration.getIgnoreList();
const index = {};
for (const [rule, scopes] of Object.entries(ignoreList)) {
index[rule] = (0, _find_schema_nodes.findSchemaNodes)(scopes, schema);
}
return error => {
if (error instanceof _validation_error.ValidationError) {
const subjects = index[error.ruleName];
const ignore = subjects === null || subjects === void 0 ? void 0 : subjects.has(error.nodes[0]);
return !ignore;
} else {
return true;
}
};
}

6

package.json
{
"name": "graphql-schema-linter",
"version": "0.5.0",
"version": "1.0.0",
"description": "Command line tool and package to validate GraphQL schemas against a set of rules.",

@@ -26,4 +26,4 @@ "author": "Christian Joudrey",

"lint-staged": "10.1.3",
"mocha": "7.1.2",
"prettier": "2.0.5"
"mocha": "8.1.2",
"prettier": "2.1.1"
},

@@ -30,0 +30,0 @@ "babel": {

@@ -37,2 +37,8 @@ # 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)

-i, --ignore <ignore list>
ignore errors for specific schema members (see "Inline rule overrides" for an alternative way to do this)
example: --ignore '{"fields-have-descriptions":["Obvious","Query.obvious","Query.something.obvious"]}'
-f, --format <format>

@@ -220,2 +226,4 @@

**Note:** If you are authoring your GraphQL schema using a tool that prevents you from adding comments, you may use the `--ignore` to obtain the same functionality.
## Built-in rules

@@ -222,0 +230,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