cjoudrey / graphql-schema-linter

Validate GraphQL schema definitions against a set of rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Support for ignore in package.json

shellscape opened this issue · comments

I must admit I'm a bit baffled as to why --ignore accepts JSON but not from package.json, where the format is also JSON. If at all possible, please consider supporting the ignore option within package.json. It would save a whole lot of headache. 🍻

Hey @shellscape, thanks for opening this issue.

This is definitely an oversight if that's the case. It might also just be missing from the README.md.

I agree that people should be able to do something like this in their package.json:

{
  "graphql-schema-linter": {
    "ignore": {
      "fields-have-descriptions": ["Obvious", "Query.obvious", "Query.something.obvious"]
    }
  }
}

If this is actually broken, I would start by looking here: https://github.com/cjoudrey/graphql-schema-linter/blob/c2876f3b93bd2a262c2af838f17cca5e21c23848/src/options.js

I took a closer look and we have a test for this use case:

describe('getIgnoreList', () => {
it('pulls ignore list from the package.json file', () => {
const options = loadOptionsFromConfigDir(
temporaryConfigDirectory({
ignore: {
'fields-have-descriptions': [
'Obvious',
'Query.obvious',
'Query.something.obvious',
],
},
})
);
const configuration = new Configuration(emptySchema, options);
const ignoreList = configuration.getIgnoreList();
assert.deepEqual(ignoreList, {
'fields-have-descriptions': [
'Obvious',
'Query.obvious',
'Query.something.obvious',
],
});
});

So either the test is broken or perhaps we're just missing some documentation in the README.md about the above use case.

Yeah my first stop was the README. The text here: https://github.com/cjoudrey/graphql-schema-linter#configuration-file, states that ignore is not an option that it accepts. So I gave it a shot anyways, and it didn't work. Triple checked the syntax and no joy. (I was ignoring an unused type). Once added on the command line option, worked as expected. So if it is supported, something is definitely off.

FWIW I tried the ignore syntax in package.json and it worked fine for me.

"graphql-schema-linter": { "ignore": { "types-have-descriptions": [ ... ] } }

Seems to work fine in package.json, but I couldn't get it to work with .graphql-schema-linterrc

I have this in my package.json, working quite alright with a TypeGraphQL generated schema.

{
"graphql-schema-linter": {
   "ignore": {
      "arguments-have-descriptions": ["Query._entities"],
      "fields-are-camel-cased": ["Query._entities", "Query._service"],
      "fields-have-descriptions": ["Query", "Mutation"],
      "types-are-capitalized": ["_Service"],
      "types-have-descriptions": ["Query", "Mutation", "_Any", "_Entity", "_Service"]
    }
  }
}