Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ 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 All @@ -56,6 +52,14 @@ Options:

path to additional custom rules to be loaded. Example: rules/*.js

--comment-descriptions

use old way of defining descriptions in GraphQL SDL

--old-implements-syntax

use old way of defining implemented interfaces in GraphQL SDL

--version

output the version number
Expand Down
6 changes: 6 additions & 0 deletions src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export class Configuration {
- customRulePaths: [string array] path to additional custom rules to be loaded
- stdin: [boolean] pass schema via stdin?
- commentDescriptions: [boolean] use old way of defining descriptions in GraphQL SDL
- oldImplementsSyntax: [boolean] use old way of defining implemented interfaces in GraphQL SDL
*/
constructor(options = {}, stdinFd = null) {
const defaultOptions = {
format: 'text',
customRulePaths: [],
commentDescriptions: false,
oldImplementsSyntax: false,
};
const configOptions = loadOptionsFromConfig(options.configDirectory);

Expand All @@ -42,6 +44,10 @@ export class Configuration {
return this.options.commentDescriptions;
}

getOldImplementsSyntax() {
return this.options.oldImplementsSyntax;
}

getSchema() {
if (this.schema) {
return this.schema;
Expand Down
8 changes: 8 additions & 0 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function run(stdout, stdin, stderr, argv) {
'--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>',
Expand Down Expand Up @@ -144,6 +148,10 @@ function getOptionsFromCommander(commander) {
options.commentDescriptions = commander.commentDescriptions;
}

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

if (commander.args && commander.args.length) {
options.schemaPaths = commander.args;
}
Expand Down
8 changes: 7 additions & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ export function validateSchemaDefinition(
configuration
) {
let ast;

let parseOptions = {};
if (configuration.getOldImplementsSyntax()) {
parseOptions.allowLegacySDLImplementsInterfaces = true;
}

try {
ast = parse(schemaDefinition);
ast = parse(schemaDefinition, parseOptions);
} catch (e) {
if (e instanceof GraphQLError) {
return [e];
Expand Down
12 changes: 12 additions & 0 deletions test/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,16 @@ extend type Query {
assert.equal(configuration.getCommentDescriptions(), true);
});
});

describe('getOldImplementsSyntax', () => {
it('defaults to false', () => {
const configuration = new Configuration({});
assert.equal(configuration.getOldImplementsSyntax(), false);
});

it('returns specified value', () => {
const configuration = new Configuration({ oldImplementsSyntax: true });
assert.equal(configuration.getOldImplementsSyntax(), true);
});
});
});
29 changes: 29 additions & 0 deletions test/fixtures/schema.new-implements.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Query
"""
type Query {
node(id: ID!): Node
posts: [Post!]!
}

"""
Post
"""
type Post implements Node & Commentable {
id: ID!
comments: [String!]!
}

"""
Node
"""
interface Node {
id: ID!
}

"""
Commentable
"""
interface Commentable {
comments: [String!]!
}
29 changes: 29 additions & 0 deletions test/fixtures/schema.old-implements.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Query
"""
type Query {
node(id: ID!): Node
posts: [Post!]!
}

"""
Post
"""
type Post implements Node, Commentable {
id: ID!
comments: [String!]!
}

"""
Node
"""
interface Node {
id: ID!
}

"""
Commentable
"""
interface Commentable {
comments: [String!]!
}
33 changes: 33 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,39 @@ describe('Runner', () => {
assert.equal(expected, stripAnsi(stdout));
});

it('allows using old `implements` syntax in GraphQL SDL', () => {
const argv = [
'node',
'lib/cli.js',
'--format',
'json',
'--old-implements-syntax',
'--rules',
'types-have-descriptions',
`${__dirname}/fixtures/schema.old-implements.graphql`,
];

run(mockStdout, mockStdin, mockStderr, argv);

assert.deepEqual([], JSON.parse(stdout)['errors']);
});

it('validates using new `implements` syntax in GraphQL SDL', () => {
const argv = [
'node',
'lib/cli.js',
'--format',
'json',
'--rules',
'types-have-descriptions',
`${__dirname}/fixtures/schema.new-implements.graphql`,
];

run(mockStdout, mockStdin, mockStderr, argv);

assert.deepEqual([], JSON.parse(stdout)['errors']);
});

it('validates a single schema file and outputs in text', () => {
const argv = [
'node',
Expand Down