Skip to content

Commit

Permalink
Add --comment-descriptions CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
cjoudrey committed Feb 12, 2018
1 parent 0da3026 commit 8124e0d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Options:
schema definition will be read from STDIN instead of specified file
--comment-descriptions
use old way of defining descriptions in GraphQL SDL
-c, --config-direction <path>
path to begin searching for config files
Expand Down
8 changes: 8 additions & 0 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function run(stdout, stdin, stderr, argv) {
'-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'
)
// DEPRECATED - This code should be removed in v1.0.0.
.option(
'-o, --only <rules>',
Expand Down Expand Up @@ -136,6 +140,10 @@ function getOptionsFromCommander(commander) {
options.customRulePaths = commander.customRulePaths.split(',');
}

if (commander.commentDescriptions) {
options.commentDescriptions = commander.commentDescriptions;
}

if (commander.args && commander.args.length) {
options.schemaPaths = commander.args;
}
Expand Down
18 changes: 10 additions & 8 deletions test/fixtures/animal.graphql
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Base query
"Base query"
type Query {
# Animal Viewing
"Animal Viewing"
viewer: Animal!
}

# Animal
"Animal"
type Animal {
# name
"name"
name: String!
# type

"type"
types: [AnimalTypes]
}

# Animal type enum
"Animal type enum"
enum AnimalTypes {
# meow
"meow"
CAT_ENUM
# woof

"woof"
DOG_ENUM
}
4 changes: 2 additions & 2 deletions test/fixtures/valid.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Query
"Query"
type Query {
# a
"a"
a: String!
}
23 changes: 22 additions & 1 deletion test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ describe('Runner', () => {
assert.equal(0, exitCode);
});

it('allows setting descriptions using comments in GraphQL SDL', () => {
const argv = [
'node',
'lib/cli.js',
'--format',
'text',
'--comment-descriptions',
`${__dirname}/fixtures/schema.comment-descriptions.graphql`,
];

run(mockStdout, mockStdin, mockStderr, argv);

const expected =
`${__dirname}/fixtures/schema.comment-descriptions.graphql\n` +
'3:3 The field `Query.a` is missing a description. fields-have-descriptions\n' +
'\n' +
'✖ 1 error detected\n';

assert.equal(expected, stripAnsi(stdout));
});

it('validates a single schema file and outputs in text', () => {
const argv = [
'node',
Expand Down Expand Up @@ -108,7 +129,7 @@ describe('Runner', () => {
const expected =
`${__dirname}/fixtures/animal.graphql\n` +
"18:3 The enum value `AnimalTypes.CAT_ENUM` cannot include the word 'enum'. enum-name-cannot-contain-enum\n" +
"20:3 The enum value `AnimalTypes.DOG_ENUM` cannot include the word 'enum'. enum-name-cannot-contain-enum\n" +
"21:3 The enum value `AnimalTypes.DOG_ENUM` cannot include the word 'enum'. enum-name-cannot-contain-enum\n" +
'\n' +
'✖ 2 errors detected\n';

Expand Down

0 comments on commit 8124e0d

Please sign in to comment.