Skip to content

Commit b6b2789

Browse files
printer: remove 'addDescription' wrapper (#2933)
1 parent 45e33ce commit b6b2789

File tree

1 file changed

+91
-77
lines changed

1 file changed

+91
-77
lines changed

src/language/printer.js

Lines changed: 91 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -106,64 +106,79 @@ const printDocASTReducer: any = {
106106

107107
// Type System Definitions
108108

109-
SchemaDefinition: addDescription(({ directives, operationTypes }) =>
109+
SchemaDefinition: ({ description, directives, operationTypes }) =>
110+
wrap('', description, '\n') +
110111
join(['schema', join(directives, ' '), block(operationTypes)], ' '),
111-
),
112112

113113
OperationTypeDefinition: ({ operation, type }) => operation + ': ' + type,
114114

115-
ScalarTypeDefinition: addDescription(({ name, directives }) =>
115+
ScalarTypeDefinition: ({ description, name, directives }) =>
116+
wrap('', description, '\n') +
116117
join(['scalar', name, join(directives, ' ')], ' '),
117-
),
118-
119-
ObjectTypeDefinition: addDescription(
120-
({ name, interfaces, directives, fields }) =>
121-
join(
122-
[
123-
'type',
124-
name,
125-
wrap('implements ', join(interfaces, ' & ')),
126-
join(directives, ' '),
127-
block(fields),
128-
],
129-
' ',
130-
),
131-
),
132-
133-
FieldDefinition: addDescription(
134-
({ name, arguments: args, type, directives }) =>
135-
name +
136-
(hasMultilineItems(args)
137-
? wrap('(\n', indent(join(args, '\n')), '\n)')
138-
: wrap('(', join(args, ', '), ')')) +
139-
': ' +
140-
type +
141-
wrap(' ', join(directives, ' ')),
142-
),
143-
144-
InputValueDefinition: addDescription(
145-
({ name, type, defaultValue, directives }) =>
146-
join(
147-
[name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')],
148-
' ',
149-
),
150-
),
151-
152-
InterfaceTypeDefinition: addDescription(
153-
({ name, interfaces, directives, fields }) =>
154-
join(
155-
[
156-
'interface',
157-
name,
158-
wrap('implements ', join(interfaces, ' & ')),
159-
join(directives, ' '),
160-
block(fields),
161-
],
162-
' ',
163-
),
164-
),
165-
166-
UnionTypeDefinition: addDescription(({ name, directives, types }) =>
118+
119+
ObjectTypeDefinition: ({
120+
description,
121+
name,
122+
interfaces,
123+
directives,
124+
fields,
125+
}) =>
126+
wrap('', description, '\n') +
127+
join(
128+
[
129+
'type',
130+
name,
131+
wrap('implements ', join(interfaces, ' & ')),
132+
join(directives, ' '),
133+
block(fields),
134+
],
135+
' ',
136+
),
137+
138+
FieldDefinition: ({ description, name, arguments: args, type, directives }) =>
139+
wrap('', description, '\n') +
140+
name +
141+
(hasMultilineItems(args)
142+
? wrap('(\n', indent(join(args, '\n')), '\n)')
143+
: wrap('(', join(args, ', '), ')')) +
144+
': ' +
145+
type +
146+
wrap(' ', join(directives, ' ')),
147+
148+
InputValueDefinition: ({
149+
description,
150+
name,
151+
type,
152+
defaultValue,
153+
directives,
154+
}) =>
155+
wrap('', description, '\n') +
156+
join(
157+
[name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')],
158+
' ',
159+
),
160+
161+
InterfaceTypeDefinition: ({
162+
description,
163+
name,
164+
interfaces,
165+
directives,
166+
fields,
167+
}) =>
168+
wrap('', description, '\n') +
169+
join(
170+
[
171+
'interface',
172+
name,
173+
wrap('implements ', join(interfaces, ' & ')),
174+
join(directives, ' '),
175+
block(fields),
176+
],
177+
' ',
178+
),
179+
180+
UnionTypeDefinition: ({ description, name, directives, types }) =>
181+
wrap('', description, '\n') +
167182
join(
168183
[
169184
'union',
@@ -173,31 +188,34 @@ const printDocASTReducer: any = {
173188
],
174189
' ',
175190
),
176-
),
177191

178-
EnumTypeDefinition: addDescription(({ name, directives, values }) =>
192+
EnumTypeDefinition: ({ description, name, directives, values }) =>
193+
wrap('', description, '\n') +
179194
join(['enum', name, join(directives, ' '), block(values)], ' '),
180-
),
181195

182-
EnumValueDefinition: addDescription(({ name, directives }) =>
183-
join([name, join(directives, ' ')], ' '),
184-
),
196+
EnumValueDefinition: ({ description, name, directives }) =>
197+
wrap('', description, '\n') + join([name, join(directives, ' ')], ' '),
185198

186-
InputObjectTypeDefinition: addDescription(({ name, directives, fields }) =>
199+
InputObjectTypeDefinition: ({ description, name, directives, fields }) =>
200+
wrap('', description, '\n') +
187201
join(['input', name, join(directives, ' '), block(fields)], ' '),
188-
),
189-
190-
DirectiveDefinition: addDescription(
191-
({ name, arguments: args, repeatable, locations }) =>
192-
'directive @' +
193-
name +
194-
(hasMultilineItems(args)
195-
? wrap('(\n', indent(join(args, '\n')), '\n)')
196-
: wrap('(', join(args, ', '), ')')) +
197-
(repeatable ? ' repeatable' : '') +
198-
' on ' +
199-
join(locations, ' | '),
200-
),
202+
203+
DirectiveDefinition: ({
204+
description,
205+
name,
206+
arguments: args,
207+
repeatable,
208+
locations,
209+
}) =>
210+
wrap('', description, '\n') +
211+
'directive @' +
212+
name +
213+
(hasMultilineItems(args)
214+
? wrap('(\n', indent(join(args, '\n')), '\n)')
215+
: wrap('(', join(args, ', '), ')')) +
216+
(repeatable ? ' repeatable' : '') +
217+
' on ' +
218+
join(locations, ' | '),
201219

202220
SchemaExtension: ({ directives, operationTypes }) =>
203221
join(['extend schema', join(directives, ' '), block(operationTypes)], ' '),
@@ -247,10 +265,6 @@ const printDocASTReducer: any = {
247265
join(['extend input', name, join(directives, ' '), block(fields)], ' '),
248266
};
249267

250-
function addDescription(cb) {
251-
return (node) => join([node.description, cb(node)], '\n');
252-
}
253-
254268
/**
255269
* Given maybeArray, print an empty string if it is null or empty, otherwise
256270
* print all items together separated by separator if provided

0 commit comments

Comments
 (0)