@@ -47,6 +47,19 @@ const MAX_LINE_LENGTH = 80;
47
47
48
48
let LF = '\n' ;
49
49
50
+ function Arguments ( length : number , node : readonly ArgumentNode [ ] ) : string {
51
+ const args = mapJoin ( node , ', ' , nodes . Argument ) ;
52
+ if ( length + args . length + 2 > MAX_LINE_LENGTH ) {
53
+ return '(' +
54
+ ( LF += ' ' ) +
55
+ mapJoin ( node , LF , nodes . Argument ) +
56
+ ( LF = LF . slice ( 0 , - 2 ) ) +
57
+ ')' ;
58
+ } else {
59
+ return '(' + args + ')' ;
60
+ }
61
+ }
62
+
50
63
const nodes = {
51
64
OperationDefinition ( node : OperationDefinitionNode ) : string {
52
65
let out : string = node . operation ;
@@ -70,19 +83,8 @@ const nodes = {
70
83
} ,
71
84
Field ( node : FieldNode ) : string {
72
85
let out = node . alias ? node . alias . value + ': ' + node . name . value : node . name . value ;
73
- if ( node . arguments && node . arguments . length ) {
74
- const args = mapJoin ( node . arguments , ', ' , nodes . Argument ) ;
75
- if ( out . length + args . length + 2 > MAX_LINE_LENGTH ) {
76
- out +=
77
- '(' +
78
- ( LF += ' ' ) +
79
- mapJoin ( node . arguments , LF , nodes . Argument ) +
80
- ( LF = LF . slice ( 0 , - 2 ) ) +
81
- ')' ;
82
- } else {
83
- out += '(' + args + ')' ;
84
- }
85
- }
86
+ if ( node . arguments && node . arguments . length )
87
+ out += Arguments ( out . length , node . arguments ) ;
86
88
if ( node . directives && node . directives . length )
87
89
out += ' ' + mapJoin ( node . directives , ' ' , nodes . Directive ) ;
88
90
if ( node . selectionSet ) out += ' ' + nodes . SelectionSet ( node . selectionSet ) ;
@@ -137,6 +139,8 @@ const nodes = {
137
139
} ,
138
140
FragmentSpread ( node : FragmentSpreadNode ) : string {
139
141
let out = '...' + node . name . value ;
142
+ if ( node . arguments && node . arguments . length )
143
+ out += Arguments ( out . length , node . arguments ) ;
140
144
if ( node . directives && node . directives . length )
141
145
out += ' ' + mapJoin ( node . directives , ' ' , nodes . Directive ) ;
142
146
return out ;
@@ -151,6 +155,8 @@ const nodes = {
151
155
} ,
152
156
FragmentDefinition ( node : FragmentDefinitionNode ) : string {
153
157
let out = 'fragment ' + node . name . value ;
158
+ if ( node . variableDefinitions && node . variableDefinitions . length )
159
+ out += '(' + mapJoin ( node . variableDefinitions , ', ' , nodes . VariableDefinition ) + ')' ;
154
160
out += ' on ' + node . typeCondition . name . value ;
155
161
if ( node . directives && node . directives . length )
156
162
out += ' ' + mapJoin ( node . directives , ' ' , nodes . Directive ) ;
0 commit comments