1
- import type { ASTNode } from './ast' ;
1
+ import type { ASTNode , ArgumentNode } from './ast' ;
2
2
3
3
export function printString ( string : string ) {
4
4
return JSON . stringify ( string ) ;
@@ -8,8 +8,8 @@ export function printBlockString(string: string) {
8
8
return '"""\n' + string . replace ( / " " " / g, '\\"""' ) + '\n"""' ;
9
9
}
10
10
11
- const hasItems = < T > ( array : ReadonlyArray < T > | undefined | null ) : array is ReadonlyArray < T > =>
12
- ! ! ( array && array . length ) ;
11
+ const hasItems = < T > ( array : unknown ) : array is ReadonlyArray < T > =>
12
+ ! ! ( array && ( array as unknown [ ] ) . length ) ;
13
13
14
14
const MAX_LINE_LENGTH = 80 ;
15
15
@@ -97,7 +97,7 @@ const nodes: {
97
97
} ,
98
98
FragmentSpread ( node ) {
99
99
let out = '...' + node . name . value ;
100
- if ( 'arguments' in node && Array . isArray ( node . arguments ) && hasItems ( node . arguments ) )
100
+ if ( 'arguments' in node && hasItems < ArgumentNode > ( node . arguments ) )
101
101
out += '(' + node . arguments . map ( nodes . Argument ! ) . join ( ', ' ) + ')' ;
102
102
if ( hasItems ( node . directives ) ) out += ' ' + node . directives . map ( nodes . Directive ! ) . join ( ' ' ) ;
103
103
return out ;
@@ -110,9 +110,8 @@ const nodes: {
110
110
} ,
111
111
FragmentDefinition ( node ) {
112
112
let out = 'fragment ' + node . name . value ;
113
- if ( hasItems ( node . variableDefinitions ) ) {
113
+ if ( hasItems ( node . variableDefinitions ) )
114
114
out += '(' + node . variableDefinitions . map ( nodes . VariableDefinition ! ) . join ( ', ' ) + ')' ;
115
- }
116
115
out += ' on ' + node . typeCondition . name . value ;
117
116
if ( hasItems ( node . directives ) ) out += ' ' + node . directives . map ( nodes . Directive ! ) . join ( ' ' ) ;
118
117
return out + ' ' + print ( node . selectionSet ) ;
0 commit comments