11// the tests in tests/graphql.js use this schema to ensure the integrity
22// of the data in src/graphql/data/*.json
33
4+ // JSON Schema type definitions for AJV validation
5+ interface JSONSchema {
6+ type ?: string
7+ required ?: string [ ]
8+ properties ?: Record < string , JSONSchema >
9+ items ?: JSONSchema
10+ pattern ?: string
11+ }
12+
13+ interface ValidatorSchema extends JSONSchema {
14+ type : 'object'
15+ required : string [ ]
16+ properties : Record < string , JSONSchema >
17+ }
18+
419// PREVIEWS
5- export const previewsValidator = {
20+ export const previewsValidator : ValidatorSchema = {
621 type : 'object' ,
722 required : [
823 'title' ,
@@ -39,7 +54,7 @@ export const previewsValidator = {
3954}
4055
4156// UPCOMING CHANGES
42- export const upcomingChangesValidator = {
57+ export const upcomingChangesValidator : ValidatorSchema = {
4358 type : 'object' ,
4459 required : [ 'location' , 'description' , 'reason' , 'date' , 'criticality' , 'owner' ] ,
4560 properties : {
@@ -69,7 +84,7 @@ export const upcomingChangesValidator = {
6984
7085// SCHEMAS
7186// many GraphQL schema members have these core properties
72- const coreProps = {
87+ const coreProps : JSONSchema = {
7388 properties : {
7489 name : {
7590 type : 'string' ,
@@ -102,7 +117,7 @@ const coreProps = {
102117// some GraphQL schema members have the core properties plus an 'args' object
103118const corePropsPlusArgs = dup ( coreProps )
104119
105- corePropsPlusArgs . properties . args = {
120+ corePropsPlusArgs . properties ! . args = {
106121 type : 'array' ,
107122 items : {
108123 type : 'object' ,
@@ -111,24 +126,24 @@ corePropsPlusArgs.properties.args = {
111126}
112127
113128// the args object can have defaultValue prop
114- corePropsPlusArgs . properties . args . items . properties . defaultValue = {
129+ corePropsPlusArgs . properties ! . args . items ! . properties ! . defaultValue = {
115130 type : 'boolean' ,
116131}
117132
118133const corePropsNoType = dup ( coreProps )
119- delete corePropsNoType . properties . type
134+ delete corePropsNoType . properties ! . type
120135
121136const corePropsNoDescription = dup ( coreProps )
122- delete corePropsNoDescription . properties . description
137+ delete corePropsNoDescription . properties ! . description
123138
124139// QUERIES
125- const queries = dup ( corePropsPlusArgs )
140+ const queries = dup ( corePropsPlusArgs ) as ValidatorSchema
126141
127142queries . type = 'object'
128143queries . required = [ 'name' , 'type' , 'kind' , 'id' , 'href' , 'description' ]
129144
130145// MUTATIONS
131- const mutations = dup ( corePropsNoType )
146+ const mutations = dup ( corePropsNoType ) as ValidatorSchema
132147
133148mutations . type = 'object'
134149mutations . required = [ 'name' , 'kind' , 'id' , 'href' , 'description' , 'inputFields' , 'returnFields' ]
@@ -150,7 +165,7 @@ mutations.properties.returnFields = {
150165}
151166
152167// OBJECTS
153- const objects = dup ( corePropsNoType )
168+ const objects = dup ( corePropsNoType ) as ValidatorSchema
154169
155170objects . type = 'object'
156171objects . required = [ 'name' , 'kind' , 'id' , 'href' , 'description' , 'fields' ]
@@ -183,7 +198,7 @@ objects.properties.implements = {
183198}
184199
185200// INTERFACES
186- const interfaces = dup ( corePropsNoType )
201+ const interfaces = dup ( corePropsNoType ) as ValidatorSchema
187202
188203interfaces . type = 'object'
189204interfaces . required = [ 'name' , 'kind' , 'id' , 'href' , 'description' , 'fields' ]
@@ -197,7 +212,7 @@ interfaces.properties.fields = {
197212}
198213
199214// ENUMS
200- const enums = dup ( corePropsNoType )
215+ const enums = dup ( corePropsNoType ) as ValidatorSchema
201216
202217enums . type = 'object'
203218enums . required = [ 'name' , 'kind' , 'id' , 'href' , 'description' , 'values' ]
@@ -219,7 +234,7 @@ enums.properties.values = {
219234}
220235
221236// UNIONS
222- const unions = dup ( corePropsNoType )
237+ const unions = dup ( corePropsNoType ) as ValidatorSchema
223238
224239unions . type = 'object'
225240unions . required = [ 'name' , 'kind' , 'id' , 'href' , 'description' , 'possibleTypes' ]
@@ -244,7 +259,7 @@ unions.properties.possibleTypes = {
244259}
245260
246261// INPUT OBJECTS
247- const inputObjects = dup ( corePropsNoType )
262+ const inputObjects = dup ( corePropsNoType ) as ValidatorSchema
248263
249264inputObjects . type = 'object'
250265inputObjects . required = [ 'name' , 'kind' , 'id' , 'href' , 'description' , 'inputFields' ]
@@ -258,16 +273,29 @@ inputObjects.properties.inputFields = {
258273}
259274
260275// SCALARS
261- const scalars = dup ( corePropsNoType )
276+ const scalars = dup ( corePropsNoType ) as ValidatorSchema
262277
263278scalars . type = 'object'
264279scalars . required = [ 'name' , 'id' , 'href' , 'description' ]
265280
266- function dup ( obj ) {
281+ // Deep clone utility function with proper typing
282+ function dup < T > ( obj : T ) : T {
267283 return JSON . parse ( JSON . stringify ( obj ) )
268284}
269285
270- export const schemaValidator = {
286+ // Schema validator collection with proper typing
287+ interface SchemaValidators {
288+ queries : ValidatorSchema
289+ mutations : ValidatorSchema
290+ objects : ValidatorSchema
291+ interfaces : ValidatorSchema
292+ enums : ValidatorSchema
293+ unions : ValidatorSchema
294+ inputObjects : ValidatorSchema
295+ scalars : ValidatorSchema
296+ }
297+
298+ export const schemaValidator : SchemaValidators = {
271299 queries,
272300 mutations,
273301 objects,
0 commit comments