From 8124e0de2268ba1d8c6268f76be73c74704f32e2 Mon Sep 17 00:00:00 2001 From: Christian Joudrey Date: Sun, 11 Feb 2018 23:39:22 -0500 Subject: [PATCH] Add --comment-descriptions CLI option --- README.md | 4 ++++ src/runner.js | 8 ++++++++ test/fixtures/animal.graphql | 18 ++++++++++-------- test/fixtures/valid.graphql | 4 ++-- test/runner.js | 23 ++++++++++++++++++++++- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cd971a6..2becc43 100644 --- a/README.md +++ b/README.md @@ -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 to begin searching for config files diff --git a/src/runner.js b/src/runner.js index f697ca3..84ae01c 100644 --- a/src/runner.js +++ b/src/runner.js @@ -28,6 +28,10 @@ export function run(stdout, stdin, stderr, argv) { '-p, --custom-rule-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 ', @@ -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; } diff --git a/test/fixtures/animal.graphql b/test/fixtures/animal.graphql index 63849c5..393dac9 100644 --- a/test/fixtures/animal.graphql +++ b/test/fixtures/animal.graphql @@ -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 } diff --git a/test/fixtures/valid.graphql b/test/fixtures/valid.graphql index ea46408..1fc23ae 100644 --- a/test/fixtures/valid.graphql +++ b/test/fixtures/valid.graphql @@ -1,5 +1,5 @@ -# Query +"Query" type Query { - # a + "a" a: String! } diff --git a/test/runner.js b/test/runner.js index 3f467a7..2186c40 100644 --- a/test/runner.js +++ b/test/runner.js @@ -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', @@ -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';