File tree Expand file tree Collapse file tree 3 files changed +88
-3
lines changed Expand file tree Collapse file tree 3 files changed +88
-3
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,72 @@ describe('Schema', () => {
2828 } ,
2929 ) ;
3030 } ) ;
31+
32+ it ( 'can modify validation rule severity' , ( done ) => {
33+ const gql = runGQLService (
34+ {
35+ '/test/schema/schema.gql' : `
36+ type Query {
37+ name: String
38+ }
39+ type Hello {
40+ name: String
41+ }
42+ ` ,
43+ '/test/.gqlconfig' : `{
44+ schema: {
45+ files: 'schema/*.gql',
46+ validate: {
47+ extends: 'gql-rules-schema',
48+ rules: {
49+ NoUnusedTypeDefinition: 'error',
50+ },
51+ }
52+ }
53+ }` ,
54+ } ,
55+ {
56+ cwd : '/test' ,
57+ onInit : ( ) => {
58+ expect ( gql . status ( ) ) . toMatchSnapshot ( ) ;
59+ done ( ) ;
60+ } ,
61+ } ,
62+ ) ;
63+ } ) ;
64+
65+ it ( 'can turn off validation rules' , ( done ) => {
66+ const gql = runGQLService (
67+ {
68+ '/test/schema/schema.gql' : `
69+ type Query {
70+ name: String
71+ }
72+ type Hello {
73+ name: String
74+ }
75+ ` ,
76+ '/test/.gqlconfig' : `{
77+ schema: {
78+ files: 'schema/*.gql',
79+ validate: {
80+ extends: 'gql-rules-schema',
81+ rules: {
82+ NoUnusedTypeDefinition: 'off',
83+ },
84+ }
85+ }
86+ }` ,
87+ } ,
88+ {
89+ cwd : '/test' ,
90+ onInit : ( ) => {
91+ expect ( gql . status ( ) ) . toMatchSnapshot ( ) ;
92+ done ( ) ;
93+ } ,
94+ } ,
95+ ) ;
96+ } ) ;
3197} ) ;
3298
3399describe ( 'Query' , ( ) => {
Original file line number Diff line number Diff line change @@ -16,6 +16,24 @@ Array [
1616]
1717` ;
1818
19+ exports [` Schema can modify validation rule severity 1` ] = `
20+ Array [
21+ Object {
22+ " locations" : Array [
23+ Object {
24+ " column" : 11 ,
25+ " line" : 5 ,
26+ " path" : " /test/schema/schema.gql" ,
27+ },
28+ ],
29+ " message" : " Unused type definition 'Hello' (NoUnusedTypeDefinition)" ,
30+ " severity" : " error" ,
31+ } ,
32+ ]
33+ ` ;
34+
35+ exports [` Schema can turn off validation rules 1` ] = ` Array []` ;
36+
1937exports [` Schema should report errors in schema 1` ] = `
2038Array [
2139 Object {
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ export default class GQLSchemaBuilder {
5454 files : config . getSchema ( ) . files ,
5555 name : 'gqlSchemaFiles' ,
5656 onChange : ( files : Array < WatchFile > ) => {
57- this . _updateFiles ( files ) ;
57+ this . _updateFiles ( files , config . getSchema ( ) ) ;
5858 // console.log('init done');
5959 if ( ! this . _isInitialized ) {
6060 this . _isInitialized = true ;
@@ -85,7 +85,7 @@ export default class GQLSchemaBuilder {
8585 }
8686
8787 // private methods
88- _updateFiles ( files : Array < WatchFile > ) {
88+ _updateFiles ( files : Array < WatchFile > , config : any ) {
8989 if ( files . length === 0 ) { return ; }
9090
9191 // console.time('updating files');
@@ -112,7 +112,8 @@ export default class GQLSchemaBuilder {
112112
113113 // validate
114114 // console.time('validate');
115- const validationErrors = validate ( schema , ast ) ;
115+ // console.log(config.validate);
116+ const validationErrors = validate ( schema , ast , config . validate ) ;
116117 // console.timeEnd('validate');
117118
118119 this . _ast = ast ;
You can’t perform that action at this time.
0 commit comments