@@ -110,113 +110,68 @@ const printDocASTReducer = {
110
110
111
111
OperationTypeDefinition : ( { operation, type } ) => operation + ': ' + type ,
112
112
113
- ScalarTypeDefinition : ( { description, name, directives } ) =>
114
- join (
115
- [ description , join ( [ 'scalar' , name , join ( directives , ' ' ) ] , ' ' ) ] ,
116
- '\n' ,
117
- ) ,
118
-
119
- ObjectTypeDefinition : ( {
120
- description,
121
- name,
122
- interfaces,
123
- directives,
124
- fields,
125
- } ) =>
126
- join (
127
- [
128
- description ,
129
- join (
130
- [
131
- 'type' ,
132
- name ,
133
- wrap ( 'implements ' , join ( interfaces , ' & ' ) ) ,
134
- join ( directives , ' ' ) ,
135
- block ( fields ) ,
136
- ] ,
137
- ' ' ,
138
- ) ,
139
- ] ,
140
- '\n' ,
141
- ) ,
142
-
143
- FieldDefinition : ( { description, name, arguments : args , type, directives } ) =>
144
- join (
145
- [
146
- description ,
147
- name +
148
- wrap ( '(' , join ( args , ', ' ) , ')' ) +
149
- ': ' +
150
- type +
151
- wrap ( ' ' , join ( directives , ' ' ) ) ,
152
- ] ,
153
- '\n' ,
154
- ) ,
155
-
156
- InputValueDefinition : ( {
157
- description,
158
- name,
159
- type,
160
- defaultValue,
161
- directives,
162
- } ) =>
163
- join (
164
- [
165
- description ,
166
- join (
167
- [ name + ': ' + type , wrap ( '= ' , defaultValue ) , join ( directives , ' ' ) ] ,
168
- ' ' ,
169
- ) ,
170
- ] ,
171
- '\n' ,
172
- ) ,
173
-
174
- InterfaceTypeDefinition : ( { description, name, directives, fields } ) =>
113
+ ScalarTypeDefinition : addDescription ( ( { name, directives } ) =>
114
+ join ( [ 'scalar' , name , join ( directives , ' ' ) ] , ' ' ) ,
115
+ ) ,
116
+
117
+ ObjectTypeDefinition : addDescription (
118
+ ( { name, interfaces, directives, fields } ) =>
119
+ join (
120
+ [
121
+ 'type' ,
122
+ name ,
123
+ wrap ( 'implements ' , join ( interfaces , ' & ' ) ) ,
124
+ join ( directives , ' ' ) ,
125
+ block ( fields ) ,
126
+ ] ,
127
+ ' ' ,
128
+ ) ,
129
+ ) ,
130
+
131
+ FieldDefinition : addDescription (
132
+ ( { name, arguments : args , type, directives } ) =>
133
+ name +
134
+ wrap ( '(' , join ( args , ', ' ) , ')' ) +
135
+ ': ' +
136
+ type +
137
+ wrap ( ' ' , join ( directives , ' ' ) ) ,
138
+ ) ,
139
+
140
+ InputValueDefinition : addDescription (
141
+ ( { name, type, defaultValue, directives } ) =>
142
+ join (
143
+ [ name + ': ' + type , wrap ( '= ' , defaultValue ) , join ( directives , ' ' ) ] ,
144
+ ' ' ,
145
+ ) ,
146
+ ) ,
147
+
148
+ InterfaceTypeDefinition : addDescription ( ( { name, directives, fields } ) =>
149
+ join ( [ 'interface' , name , join ( directives , ' ' ) , block ( fields ) ] , ' ' ) ,
150
+ ) ,
151
+
152
+ UnionTypeDefinition : addDescription ( ( { name, directives, types } ) =>
175
153
join (
176
154
[
177
- description ,
178
- join ( [ 'interface' , name , join ( directives , ' ' ) , block ( fields ) ] , ' ' ) ,
155
+ 'union' ,
156
+ name ,
157
+ join ( directives , ' ' ) ,
158
+ types && types . length !== 0 ? '= ' + join ( types , ' | ' ) : '' ,
179
159
] ,
180
- '\n ' ,
160
+ ' ' ,
181
161
) ,
162
+ ) ,
182
163
183
- UnionTypeDefinition : ( { description, name, directives, types } ) =>
184
- join (
185
- [
186
- description ,
187
- join (
188
- [
189
- 'union' ,
190
- name ,
191
- join ( directives , ' ' ) ,
192
- types && types . length !== 0 ? '= ' + join ( types , ' | ' ) : '' ,
193
- ] ,
194
- ' ' ,
195
- ) ,
196
- ] ,
197
- '\n' ,
198
- ) ,
164
+ EnumTypeDefinition : addDescription ( ( { name, directives, values } ) =>
165
+ join ( [ 'enum' , name , join ( directives , ' ' ) , block ( values ) ] , ' ' ) ,
166
+ ) ,
199
167
200
- EnumTypeDefinition : ( { description, name, directives, values } ) =>
201
- join (
202
- [
203
- description ,
204
- join ( [ 'enum' , name , join ( directives , ' ' ) , block ( values ) ] , ' ' ) ,
205
- ] ,
206
- '\n' ,
207
- ) ,
168
+ EnumValueDefinition : addDescription ( ( { name, directives } ) =>
169
+ join ( [ name , join ( directives , ' ' ) ] , ' ' ) ,
170
+ ) ,
208
171
209
- EnumValueDefinition : ( { description, name, directives } ) =>
210
- join ( [ description , join ( [ name , join ( directives , ' ' ) ] , ' ' ) ] , '\n' ) ,
211
-
212
- InputObjectTypeDefinition : ( { description, name, directives, fields } ) =>
213
- join (
214
- [
215
- description ,
216
- join ( [ 'input' , name , join ( directives , ' ' ) , block ( fields ) ] , ' ' ) ,
217
- ] ,
218
- '\n' ,
219
- ) ,
172
+ InputObjectTypeDefinition : addDescription ( ( { name, directives, fields } ) =>
173
+ join ( [ 'input' , name , join ( directives , ' ' ) , block ( fields ) ] , ' ' ) ,
174
+ ) ,
220
175
221
176
ScalarTypeExtension : ( { name, directives } ) =>
222
177
join ( [ 'extend scalar' , name , join ( directives , ' ' ) ] , ' ' ) ,
@@ -253,20 +208,20 @@ const printDocASTReducer = {
253
208
InputObjectTypeExtension : ( { name, directives, fields } ) =>
254
209
join ( [ 'extend input' , name , join ( directives , ' ' ) , block ( fields ) ] , ' ' ) ,
255
210
256
- DirectiveDefinition : ( { description, name, arguments : args , locations } ) =>
257
- join (
258
- [
259
- description ,
260
- 'directive @' +
261
- name +
262
- wrap ( '(' , join ( args , ', ' ) , ')' ) +
263
- ' on ' +
264
- join ( locations , ' | ' ) ,
265
- ] ,
266
- '\n' ,
267
- ) ,
211
+ DirectiveDefinition : addDescription (
212
+ ( { name, arguments : args , locations } ) =>
213
+ 'directive @' +
214
+ name +
215
+ wrap ( '(' , join ( args , ', ' ) , ')' ) +
216
+ ' on ' +
217
+ join ( locations , ' | ' ) ,
218
+ ) ,
268
219
} ;
269
220
221
+ function addDescription ( cb ) {
222
+ return node => join ( [ node . description , cb ( node ) ] , '\n' ) ;
223
+ }
224
+
270
225
/**
271
226
* Given maybeArray, print an empty string if it is null or empty, otherwise
272
227
* print all items together separated by separator if provided
0 commit comments