Skip to content

Commit

Permalink
fix(schema): fix schema ignoring 'validate' options and using default…
Browse files Browse the repository at this point in the history
…Options always.

Closes #15
  • Loading branch information
Mayank1791989 committed May 15, 2017
1 parent 86443e4 commit a853032
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
66 changes: 66 additions & 0 deletions src/__tests__/GQLService_status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,72 @@ describe('Schema', () => {
},
);
});

it('can modify validation rule severity', (done) => {
const gql = runGQLService(
{
'/test/schema/schema.gql': `
type Query {
name: String
}
type Hello {
name: String
}
`,
'/test/.gqlconfig': `{
schema: {
files: 'schema/*.gql',
validate: {
extends: 'gql-rules-schema',
rules: {
NoUnusedTypeDefinition: 'error',
},
}
}
}`,
},
{
cwd: '/test',
onInit: () => {
expect(gql.status()).toMatchSnapshot();
done();
},
},
);
});

it('can turn off validation rules', (done) => {
const gql = runGQLService(
{
'/test/schema/schema.gql': `
type Query {
name: String
}
type Hello {
name: String
}
`,
'/test/.gqlconfig': `{
schema: {
files: 'schema/*.gql',
validate: {
extends: 'gql-rules-schema',
rules: {
NoUnusedTypeDefinition: 'off',
},
}
}
}`,
},
{
cwd: '/test',
onInit: () => {
expect(gql.status()).toMatchSnapshot();
done();
},
},
);
});
});

describe('Query', () => {
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/__snapshots__/GQLService_status.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ Array [
]
`;

exports[`Schema can modify validation rule severity 1`] = `
Array [
Object {
"locations": Array [
Object {
"column": 11,
"line": 5,
"path": "/test/schema/schema.gql",
},
],
"message": "Unused type definition 'Hello' (NoUnusedTypeDefinition)",
"severity": "error",
},
]
`;

exports[`Schema can turn off validation rules 1`] = `Array []`;

exports[`Schema should report errors in schema 1`] = `
Array [
Object {
Expand Down
7 changes: 4 additions & 3 deletions src/schema/SchemaBuilder/GQLSchemaBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class GQLSchemaBuilder {
files: config.getSchema().files,
name: 'gqlSchemaFiles',
onChange: (files: Array<WatchFile>) => {
this._updateFiles(files);
this._updateFiles(files, config.getSchema());
// console.log('init done');
if (!this._isInitialized) {
this._isInitialized = true;
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class GQLSchemaBuilder {
}

// private methods
_updateFiles(files: Array<WatchFile>) {
_updateFiles(files: Array<WatchFile>, config: any) {
if (files.length === 0) { return; }

// console.time('updating files');
Expand All @@ -112,7 +112,8 @@ export default class GQLSchemaBuilder {

// validate
// console.time('validate');
const validationErrors = validate(schema, ast);
// console.log(config.validate);
const validationErrors = validate(schema, ast, config.validate);
// console.timeEnd('validate');

this._ast = ast;
Expand Down

0 comments on commit a853032

Please # to comment.