@@ -24,21 +24,6 @@ export interface Annotated {
24
24
) : Annotation | undefined ;
25
25
}
26
26
27
- // DescribableNode are nodes that have descriptions associated with them.
28
- export interface DescribableNode {
29
- getDescription ( ) : StringValue ;
30
- }
31
-
32
- export interface TypeDefinition extends DescribableNode {
33
- getKind ( ) : Kind ;
34
- getLoc ( ) : Location ;
35
- }
36
-
37
- export interface TypeSystemDefinition {
38
- getKind ( ) : Kind ;
39
- getLoc ( ) : Location ;
40
- }
41
-
42
27
export class NamespaceDefinition extends AbstractNode implements Annotated {
43
28
name : Name ;
44
29
description ?: StringValue ;
@@ -78,13 +63,13 @@ export class AliasDefinition extends AbstractNode implements Annotated {
78
63
constructor (
79
64
loc : Location | undefined ,
80
65
name : Name ,
81
- desc : StringValue | undefined ,
66
+ description : StringValue | undefined ,
82
67
type : Type ,
83
68
annotations ?: Annotation [ ]
84
69
) {
85
70
super ( Kind . AliasDefinition , loc ) ;
86
71
this . name = name ;
87
- this . description = desc ;
72
+ this . description = description ;
88
73
this . type = type ;
89
74
this . annotations = annotations || [ ] ;
90
75
}
@@ -106,19 +91,19 @@ export class ImportDefinition extends AbstractNode implements Annotated {
106
91
description ?: StringValue ;
107
92
all : boolean ;
108
93
names : ImportName [ ] ;
109
- from : Name ;
94
+ from : StringValue ;
110
95
annotations ?: Annotation [ ] ;
111
96
112
97
constructor (
113
98
loc : Location | undefined ,
114
- desc : StringValue | undefined ,
99
+ description : StringValue | undefined ,
115
100
all : boolean ,
116
101
names : ImportName [ ] ,
117
- from : Name ,
102
+ from : StringValue ,
118
103
annotations ?: Annotation [ ]
119
104
) {
120
105
super ( Kind . ImportDefinition , loc ) ;
121
- this . description = desc ;
106
+ this . description = description ;
122
107
this . all = all ;
123
108
this . names = names ;
124
109
this . from = from ;
@@ -184,80 +169,6 @@ export class TypeDefinition extends AbstractNode implements Annotated {
184
169
}
185
170
}
186
171
187
- export class OperationDefinition extends AbstractNode implements Annotated {
188
- name : Name ;
189
- description : StringValue | undefined ;
190
- parameters : ParameterDefinition [ ] ;
191
- type : Type ;
192
- annotations : Annotation [ ] ;
193
- unary : boolean ;
194
-
195
- constructor (
196
- loc : Location | undefined ,
197
- name : Name ,
198
- desc : StringValue | undefined ,
199
- parameters : ParameterDefinition [ ] ,
200
- type : Type ,
201
- annotations : Annotation [ ] ,
202
- unary : boolean
203
- ) {
204
- super ( Kind . OperationDefinition , loc ) ;
205
- this . name = name ;
206
- this . description = desc ;
207
- this . parameters = parameters ;
208
- this . type = type ;
209
- this . annotations = annotations ;
210
- this . unary = unary ;
211
- }
212
-
213
- public isUnary ( ) : boolean {
214
- return this . unary && this . parameters && this . parameters . length == 1 ;
215
- }
216
-
217
- public unaryOp ( ) : ParameterDefinition {
218
- return this . parameters [ 0 ] ;
219
- }
220
-
221
- mapTypeToTranslation (
222
- typeTranslation : ( inp : Type ) => string
223
- ) : Map < String , String > {
224
- const mp = new Map < String , String > ( ) ;
225
- if ( this . unary ) {
226
- mp . set ( this . unaryOp ( ) . name . value , typeTranslation ( this . unaryOp ( ) . type ) ) ;
227
- } else {
228
- this . parameters . forEach ( ( arg ) => {
229
- mp . set ( arg . name . value , typeTranslation ( arg . type ) ) ;
230
- } ) ;
231
- }
232
- return mp ;
233
- }
234
-
235
- annotation (
236
- name : string ,
237
- callback ?: ( annotation : Annotation ) => void
238
- ) : Annotation | undefined {
239
- return getAnnotation ( name , this . annotations , callback ) ;
240
- }
241
-
242
- public accept ( context : Context , visitor : Visitor ) : void {
243
- visitor . visitOperationBefore ( context ) ;
244
- visitor . visitOperation ( context ) ;
245
-
246
- context = context . clone ( { parameters : context . operation ! . parameters } ) ;
247
- visitor . visitParametersBefore ( context ) ;
248
- context . parameters ! . map ( ( parameter , index ) => {
249
- parameter . accept (
250
- context . clone ( { parameter : parameter , parameterIndex : index } ) ,
251
- visitor
252
- ) ;
253
- } ) ;
254
- visitor . visitParametersAfter ( context ) ;
255
-
256
- visitAnnotations ( context , visitor , this . annotations ) ;
257
- visitor . visitOperationAfter ( context ) ;
258
- }
259
- }
260
-
261
172
export abstract class ValuedDefinition
262
173
extends AbstractNode
263
174
implements Annotated {
@@ -299,9 +210,9 @@ export class FieldDefinition extends ValuedDefinition {
299
210
desc : StringValue | undefined ,
300
211
type : Type ,
301
212
defaultVal : Value | undefined ,
302
- directives : Annotation [ ]
213
+ annotations : Annotation [ ]
303
214
) {
304
- super ( Kind . FieldDefinition , loc , name , desc , type , defaultVal , directives ) ;
215
+ super ( Kind . FieldDefinition , loc , name , desc , type , defaultVal , annotations ) ;
305
216
}
306
217
307
218
public accept ( context : Context , visitor : Visitor ) : void {
@@ -310,36 +221,6 @@ export class FieldDefinition extends ValuedDefinition {
310
221
}
311
222
}
312
223
313
- export class ParameterDefinition extends ValuedDefinition {
314
- constructor (
315
- loc : Location | undefined ,
316
- name : Name ,
317
- desc : StringValue | undefined ,
318
- type : Type ,
319
- defaultVal : Value | undefined ,
320
- directives : Annotation [ ]
321
- ) {
322
- super (
323
- Kind . ParameterDefinition ,
324
- loc ,
325
- name ,
326
- desc ,
327
- type ,
328
- defaultVal ,
329
- directives
330
- ) ;
331
- }
332
-
333
- public accept ( context : Context , visitor : Visitor ) : void {
334
- if ( context . operation != undefined ) {
335
- visitor . visitParameter ( context ) ;
336
- } else if ( context . directive != undefined ) {
337
- visitor . visitDirectiveParameter ( context ) ;
338
- }
339
- visitAnnotations ( context , visitor , this . annotations ) ;
340
- }
341
- }
342
-
343
224
export class InterfaceDefinition
344
225
extends AbstractNode
345
226
implements Definition , Annotated {
@@ -427,20 +308,124 @@ export class RoleDefinition
427
308
}
428
309
}
429
310
311
+ export class OperationDefinition extends AbstractNode implements Annotated {
312
+ name : Name ;
313
+ description : StringValue | undefined ;
314
+ parameters : ParameterDefinition [ ] ;
315
+ type : Type ;
316
+ annotations : Annotation [ ] ;
317
+ unary : boolean ;
318
+
319
+ constructor (
320
+ loc : Location | undefined ,
321
+ name : Name ,
322
+ desc : StringValue | undefined ,
323
+ type : Type ,
324
+ annotations : Annotation [ ] ,
325
+ unary : boolean ,
326
+ parameters : ParameterDefinition [ ]
327
+ ) {
328
+ super ( Kind . OperationDefinition , loc ) ;
329
+ this . name = name ;
330
+ this . description = desc ;
331
+ this . type = type ;
332
+ this . annotations = annotations ;
333
+ this . parameters = parameters ;
334
+ this . unary = unary ;
335
+ }
336
+
337
+ public isUnary ( ) : boolean {
338
+ return this . unary && this . parameters && this . parameters . length == 1 ;
339
+ }
340
+
341
+ public unaryOp ( ) : ParameterDefinition {
342
+ return this . parameters [ 0 ] ;
343
+ }
344
+
345
+ mapTypeToTranslation (
346
+ typeTranslation : ( inp : Type ) => string
347
+ ) : Map < String , String > {
348
+ const mp = new Map < String , String > ( ) ;
349
+ if ( this . unary ) {
350
+ mp . set ( this . unaryOp ( ) . name . value , typeTranslation ( this . unaryOp ( ) . type ) ) ;
351
+ } else {
352
+ this . parameters . forEach ( ( arg ) => {
353
+ mp . set ( arg . name . value , typeTranslation ( arg . type ) ) ;
354
+ } ) ;
355
+ }
356
+ return mp ;
357
+ }
358
+
359
+ annotation (
360
+ name : string ,
361
+ callback ?: ( annotation : Annotation ) => void
362
+ ) : Annotation | undefined {
363
+ return getAnnotation ( name , this . annotations , callback ) ;
364
+ }
365
+
366
+ public accept ( context : Context , visitor : Visitor ) : void {
367
+ visitor . visitOperationBefore ( context ) ;
368
+ visitor . visitOperation ( context ) ;
369
+
370
+ context = context . clone ( { parameters : context . operation ! . parameters } ) ;
371
+ visitor . visitParametersBefore ( context ) ;
372
+ context . parameters ! . map ( ( parameter , index ) => {
373
+ parameter . accept (
374
+ context . clone ( { parameter : parameter , parameterIndex : index } ) ,
375
+ visitor
376
+ ) ;
377
+ } ) ;
378
+ visitor . visitParametersAfter ( context ) ;
379
+
380
+ visitAnnotations ( context , visitor , this . annotations ) ;
381
+ visitor . visitOperationAfter ( context ) ;
382
+ }
383
+ }
384
+
385
+ export class ParameterDefinition extends ValuedDefinition {
386
+ constructor (
387
+ loc : Location | undefined ,
388
+ name : Name ,
389
+ desc : StringValue | undefined ,
390
+ type : Type ,
391
+ defaultVal : Value | undefined ,
392
+ annotations : Annotation [ ]
393
+ ) {
394
+ super (
395
+ Kind . ParameterDefinition ,
396
+ loc ,
397
+ name ,
398
+ desc ,
399
+ type ,
400
+ defaultVal ,
401
+ annotations
402
+ ) ;
403
+ }
404
+
405
+ public accept ( context : Context , visitor : Visitor ) : void {
406
+ if ( context . operation != undefined ) {
407
+ visitor . visitParameter ( context ) ;
408
+ } else if ( context . directive != undefined ) {
409
+ visitor . visitDirectiveParameter ( context ) ;
410
+ }
411
+ visitAnnotations ( context , visitor , this . annotations ) ;
412
+ }
413
+ }
414
+
430
415
export class UnionDefinition
431
416
extends AbstractNode
432
417
implements Definition , Annotated {
433
418
name : Name ;
434
419
description ?: StringValue ;
435
420
annotations : Annotation [ ] ;
436
- types : Named [ ] ;
421
+ types : Type [ ] ;
437
422
438
423
constructor (
439
424
loc : Location | undefined ,
440
425
name : Name ,
441
426
desc : StringValue | undefined ,
442
427
annotations : Annotation [ ] ,
443
- types : Named [ ]
428
+ types : Type [ ]
444
429
) {
445
430
super ( Kind . UnionDefinition , loc ) ;
446
431
this . name = name ;
0 commit comments