cjoudrey / graphql-schema-linter

Validate GraphQL schema definitions against a set of rules
MIT License
694 stars 62 forks source link

Not possible to ignore custom rules? #265

Closed steverice closed 3 years ago

steverice commented 3 years ago

240 added a block of code that filters out errors if they are in the ignore list, but only if they are an instanceof ValidationError:

if (error instanceof ValidationError) {
  …
} else {
  return true;
}

Presumably, this is so that plain GraphQLErrors cannot be accidentally ignored. However, this seems to make it impossible to ignore any custom rules.

The ValidationError object that's referenced here is the object exported by src/validation_error.js in graphql-schema-linter. As graphql-schema-linter is expected to be installed globally, other code (where custom rules may live) will be unable to import this reference, at least not without some ugly workarounds.

Theoretically, if the package also containing the custom rules is installed globally, or if graphql-schema-linter is being run from the same node_modules directory as the custom rule, it would work — but I don't believe this was an intentional restriction.

Am I missing something here? Would it be better to replace the instanceof check with something like checking if ruleName is defined?

cc @id-ilych

cjoudrey commented 3 years ago

Hey @steverice, thanks for opening this issue.

I think this might indeed have been an oversight. Good catch!

Checking for ruleName being defined seems better for the use case you mentioned.

Would you mind opening a PR for this?

steverice commented 3 years ago

Sure thing. #267 should fix this.