Skip to content

Commit c802ab1

Browse files
committed
Cleanup
1 parent 595d7c6 commit c802ab1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/parser.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ function variableDefinitions(): ast.VariableDefinitionNode[] | undefined {
424424
let _description: ast.StringValueNode | undefined;
425425
if (input.charCodeAt(idx) === 34 /*'"'*/) {
426426
_description = value(true) as ast.StringValueNode;
427+
if (_description.kind !== ('StringValue' as Kind.STRING)) {
428+
throw error('VariableDefinition');
429+
}
427430
}
428431
if (input.charCodeAt(idx++) !== 36 /*'$'*/) throw error('Variable');
429432
const name = nameNode();
@@ -437,7 +440,7 @@ function variableDefinitions(): ast.VariableDefinitionNode[] | undefined {
437440
_defaultValue = value(true);
438441
}
439442
ignored();
440-
const varDef: any = {
443+
const varDef: ast.VariableDefinitionNode = {
441444
kind: 'VariableDefinition' as Kind.VARIABLE_DEFINITION,
442445
variable: {
443446
kind: 'Variable' as Kind.VARIABLE,
@@ -463,7 +466,7 @@ function fragmentDefinition(description?: ast.StringValueNode): ast.FragmentDefi
463466
if (input.charCodeAt(idx++) !== 111 /*'o'*/ || input.charCodeAt(idx++) !== 110 /*'n'*/)
464467
throw error('FragmentDefinition');
465468
ignored();
466-
const fragDef: any = {
469+
const fragDef: ast.FragmentDefinitionNode = {
467470
kind: 'FragmentDefinition' as Kind.FRAGMENT_DEFINITION,
468471
name,
469472
typeCondition: {
@@ -503,11 +506,17 @@ function definitions(): ast.DefinitionNode[] {
503506
const definition = name();
504507
switch (definition) {
505508
case 'fragment':
509+
if (_description && _description.kind !== ('StringValue' as Kind.STRING)) {
510+
throw error('FragmentDefinition');
511+
}
506512
_definitions.push(fragmentDefinition(_description));
507513
break;
508514
case 'query':
509515
case 'mutation':
510516
case 'subscription':
517+
if (_description && _description.kind !== ('StringValue' as Kind.STRING)) {
518+
throw error('OperationDefinition');
519+
}
511520
let char: number;
512521
let name: ast.NameNode | undefined;
513522
if (

src/printer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ let LF = '\n';
5050
const nodes = {
5151
OperationDefinition(node: OperationDefinitionNode): string {
5252
let out: string = '';
53-
if ((node as any).description) {
54-
out += nodes.StringValue((node as any).description) + '\n';
53+
if (node.description) {
54+
out += nodes.StringValue(node.description) + '\n';
5555
}
5656
out += node.operation;
5757
if (node.name) out += ' ' + node.name.value;
@@ -66,8 +66,8 @@ const nodes = {
6666
},
6767
VariableDefinition(node: VariableDefinitionNode): string {
6868
let out = '';
69-
if ((node as any).description) {
70-
out += nodes.StringValue((node as any).description) + ' ';
69+
if (node.description) {
70+
out += nodes.StringValue(node.description) + ' ';
7171
}
7272
out += nodes.Variable!(node.variable) + ': ' + _print(node.type);
7373
if (node.defaultValue) out += ' = ' + _print(node.defaultValue);
@@ -160,8 +160,8 @@ const nodes = {
160160
},
161161
FragmentDefinition(node: FragmentDefinitionNode): string {
162162
let out = '';
163-
if ((node as any).description) {
164-
out += nodes.StringValue((node as any).description) + '\n';
163+
if (node.description) {
164+
out += nodes.StringValue(node.description) + '\n';
165165
}
166166
out += 'fragment ' + node.name.value;
167167
out += ' on ' + node.typeCondition.name.value;

0 commit comments

Comments
 (0)