graphql 15.10.3 → 15.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/error/GraphQLError.js +7 -6
- package/error/GraphQLError.js.flow +3 -3
- package/error/GraphQLError.mjs +8 -7
- package/execution/execute.d.ts +2 -0
- package/execution/execute.js +33 -12
- package/execution/execute.js.flow +32 -11
- package/execution/execute.mjs +33 -12
- package/execution/values.d.ts +1 -1
- package/execution/values.js +5 -5
- package/execution/values.js.flow +5 -2
- package/execution/values.mjs +4 -4
- package/graphql.d.ts +1 -0
- package/graphql.js +4 -1
- package/graphql.js.flow +5 -1
- package/graphql.mjs +4 -1
- package/jsutils/SetMap.js +56 -0
- package/jsutils/SetMap.js.flow +39 -0
- package/jsutils/SetMap.mjs +47 -0
- package/language/lexer.js +21 -2
- package/language/lexer.js.flow +24 -2
- package/language/lexer.mjs +21 -2
- package/language/location.d.ts +5 -0
- package/language/location.js +64 -0
- package/language/location.js.flow +39 -0
- package/language/location.mjs +62 -0
- package/language/parser.js +34 -19
- package/language/parser.js.flow +54 -10
- package/language/parser.mjs +34 -19
- package/language/printer.d.ts +7 -0
- package/language/printer.js +251 -118
- package/language/printer.js.flow +345 -141
- package/language/printer.mjs +246 -116
- package/language/reducer.js +99 -0
- package/language/reducer.js.flow +89 -0
- package/language/reducer.mjs +89 -0
- package/package.json +1 -1
- package/subscription/subscribe.d.ts +2 -0
- package/subscription/subscribe.js +4 -3
- package/subscription/subscribe.js.flow +6 -0
- package/subscription/subscribe.mjs +4 -3
- package/type/definition.d.ts +2 -1
- package/type/definition.js +8 -8
- package/type/definition.js.flow +13 -7
- package/type/definition.mjs +7 -7
- package/type/scalars.js +5 -5
- package/type/scalars.js.flow +1 -1
- package/type/scalars.mjs +1 -1
- package/utilities/buildASTSchema.js +3 -0
- package/utilities/buildASTSchema.js.flow +3 -0
- package/utilities/buildASTSchema.mjs +3 -0
- package/utilities/coerceInputValue.d.ts +1 -0
- package/utilities/coerceInputValue.js +9 -8
- package/utilities/coerceInputValue.js.flow +42 -9
- package/utilities/coerceInputValue.mjs +10 -9
- package/utilities/findBreakingChanges.js +3 -23
- package/utilities/findBreakingChanges.js.flow +2 -15
- package/utilities/findBreakingChanges.mjs +2 -21
- package/utilities/sortValueNode.js +52 -0
- package/utilities/sortValueNode.js.flow +42 -0
- package/utilities/sortValueNode.mjs +42 -0
- package/utilities/valueFromAST.js +2 -2
- package/utilities/valueFromAST.js.flow +8 -2
- package/utilities/valueFromAST.mjs +2 -2
- package/validation/ValidationContext.d.ts +8 -0
- package/validation/ValidationContext.js +82 -24
- package/validation/ValidationContext.js.flow +70 -21
- package/validation/ValidationContext.mjs +80 -24
- package/validation/rules/FieldsOnCorrectTypeRule.js +2 -2
- package/validation/rules/FieldsOnCorrectTypeRule.js.flow +8 -2
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -2
- package/validation/rules/KnownArgumentNamesRule.js +8 -9
- package/validation/rules/KnownArgumentNamesRule.js.flow +16 -6
- package/validation/rules/KnownArgumentNamesRule.mjs +8 -9
- package/validation/rules/KnownTypeNamesRule.js +1 -1
- package/validation/rules/KnownTypeNamesRule.js.flow +6 -4
- package/validation/rules/KnownTypeNamesRule.mjs +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.js +37 -17
- package/validation/rules/MaxIntrospectionDepthRule.js.flow +46 -15
- package/validation/rules/MaxIntrospectionDepthRule.mjs +37 -17
- package/validation/rules/NoUnusedFragmentsRule.js +6 -13
- package/validation/rules/NoUnusedFragmentsRule.js.flow +6 -10
- package/validation/rules/NoUnusedFragmentsRule.mjs +6 -13
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +402 -208
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +566 -330
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +400 -206
- package/validation/rules/ValuesOfCorrectTypeRule.js +6 -6
- package/validation/rules/ValuesOfCorrectTypeRule.js.flow +11 -6
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +4 -4
- package/validation/validate.d.ts +1 -1
- package/validation/validate.js +6 -2
- package/validation/validate.js.flow +8 -2
- package/validation/validate.mjs +5 -2
- package/validation/validationAbortedError.d.ts +4 -0
- package/validation/validationAbortedError.js +12 -0
- package/validation/validationAbortedError.js.flow +7 -0
- package/validation/validationAbortedError.mjs +4 -0
- package/version.js +3 -3
- package/version.js.flow +3 -3
- package/version.mjs +3 -3
package/language/printer.js.flow
CHANGED
|
@@ -1,66 +1,171 @@
|
|
|
1
1
|
// @flow strict
|
|
2
|
-
|
|
2
|
+
/** @category Printing */
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { ASTNode } from './ast';
|
|
5
5
|
import { printBlockString } from './blockString';
|
|
6
|
+
import { reduce } from './reducer';
|
|
7
|
+
|
|
8
|
+
type Maybe<+T> = ?T;
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
|
-
* Converts an AST into a string
|
|
9
|
-
*
|
|
11
|
+
* Converts an AST into a string. Indentation and inserted newlines can be
|
|
12
|
+
* limited with maxIndentDepth; the default is unlimited.
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
declare function print(
|
|
15
|
+
ast: ASTNode,
|
|
16
|
+
options: { maxIndentDepth?: number, ... },
|
|
17
|
+
): string;
|
|
18
|
+
// eslint-disable-next-line no-redeclare
|
|
19
|
+
declare function print(ast: ASTNode): string;
|
|
20
|
+
// eslint-disable-next-line no-redeclare
|
|
21
|
+
export function print(ast, options) {
|
|
22
|
+
return render(
|
|
23
|
+
reduce(ast, printDocASTReducer),
|
|
24
|
+
options?.maxIndentDepth ?? Infinity,
|
|
25
|
+
);
|
|
13
26
|
}
|
|
14
27
|
|
|
28
|
+
/** @internal */
|
|
29
|
+
export function printForError(ast: ASTNode): string {
|
|
30
|
+
return print(ast, { maxIndentDepth: 100 });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The wrapping limit applies to total string length, including newlines.
|
|
15
34
|
const MAX_LINE_LENGTH = 80;
|
|
16
35
|
|
|
17
|
-
|
|
36
|
+
class PrintBuffer {
|
|
37
|
+
length: number;
|
|
38
|
+
newlines: number;
|
|
39
|
+
lines: string | $ReadOnlyArray<string>;
|
|
40
|
+
next: PrintBuffer | void;
|
|
41
|
+
tail: PrintBuffer | void;
|
|
42
|
+
indentBefore: boolean;
|
|
43
|
+
dedentAfter: boolean;
|
|
44
|
+
isBlockString: boolean;
|
|
45
|
+
|
|
46
|
+
constructor(value = '', isBlockString = false) {
|
|
47
|
+
this.next = undefined;
|
|
48
|
+
this.indentBefore = false;
|
|
49
|
+
this.dedentAfter = false;
|
|
50
|
+
this.length = value.length;
|
|
51
|
+
this.lines = value.includes('\n') ? value.split('\n') : value;
|
|
52
|
+
this.newlines = typeof this.lines === 'string' ? 0 : this.lines.length - 1;
|
|
53
|
+
this.isBlockString = isBlockString;
|
|
54
|
+
this.tail = undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
append(result: string | PrintBuffer): this {
|
|
58
|
+
if (result.length === 0) {
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
const next = typeof result === 'string' ? new PrintBuffer(result) : result;
|
|
62
|
+
(this.tail ?? this).next = next;
|
|
63
|
+
this.tail = next.tail ?? next;
|
|
64
|
+
this.length += next.length;
|
|
65
|
+
this.newlines += next.newlines;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
indent(): this {
|
|
70
|
+
if (this.length === 0) {
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
this.indentBefore = true;
|
|
74
|
+
(this.tail ?? this).dedentAfter = true;
|
|
75
|
+
this.length += 2 * (this.newlines + 1);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const EMPTY = new PrintBuffer();
|
|
81
|
+
|
|
82
|
+
function render(buffer: PrintBuffer, maxDepth: number): string {
|
|
83
|
+
let output = '';
|
|
84
|
+
let text = '';
|
|
85
|
+
let depth = 0;
|
|
86
|
+
let indentation = '';
|
|
87
|
+
let part: PrintBuffer | void = buffer;
|
|
88
|
+
while (part !== undefined) {
|
|
89
|
+
const lines = part.lines;
|
|
90
|
+
if (part.indentBefore) {
|
|
91
|
+
if (depth < maxDepth) {
|
|
92
|
+
indentation += ' ';
|
|
93
|
+
text += ' ';
|
|
94
|
+
}
|
|
95
|
+
depth++;
|
|
96
|
+
}
|
|
97
|
+
if (typeof lines === 'string') {
|
|
98
|
+
text += lines;
|
|
99
|
+
} else {
|
|
100
|
+
text += lines[0];
|
|
101
|
+
const newline =
|
|
102
|
+
!part.isBlockString && depth >= maxDepth ? ' ' : '\n' + indentation;
|
|
103
|
+
for (let i = 1; i < lines.length; i++) {
|
|
104
|
+
output += text;
|
|
105
|
+
text = newline + lines[i];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (part.dedentAfter) {
|
|
109
|
+
depth--;
|
|
110
|
+
indentation = indentation.slice(0, depth * 2);
|
|
111
|
+
}
|
|
112
|
+
part = part.next;
|
|
113
|
+
}
|
|
114
|
+
return output + text;
|
|
115
|
+
}
|
|
116
|
+
|
|
18
117
|
const printDocASTReducer: any = {
|
|
19
|
-
Name: (node) => node.value,
|
|
20
|
-
Variable: (node) => '$'
|
|
118
|
+
Name: (node) => new PrintBuffer(node.value),
|
|
119
|
+
Variable: (node) => join(['$', node.name]),
|
|
21
120
|
|
|
22
121
|
// Document
|
|
23
122
|
|
|
24
|
-
Document: (node) => join(node.definitions, '\n\n')
|
|
123
|
+
Document: (node) => join([join(node.definitions, '\n\n'), '\n']),
|
|
25
124
|
|
|
26
125
|
OperationDefinition(node) {
|
|
27
|
-
const op = node.operation;
|
|
28
|
-
const name = node.name;
|
|
29
126
|
const varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
|
|
30
127
|
const directives = join(node.directives, ' ');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
? selectionSet
|
|
36
|
-
: join(
|
|
128
|
+
return !node.name &&
|
|
129
|
+
directives.length === 0 &&
|
|
130
|
+
varDefs.length === 0 &&
|
|
131
|
+
node.operation === 'query'
|
|
132
|
+
? node.selectionSet
|
|
133
|
+
: join(
|
|
134
|
+
[
|
|
135
|
+
node.operation,
|
|
136
|
+
join([node.name, varDefs]),
|
|
137
|
+
directives,
|
|
138
|
+
node.selectionSet,
|
|
139
|
+
],
|
|
140
|
+
' ',
|
|
141
|
+
);
|
|
37
142
|
},
|
|
38
143
|
|
|
39
144
|
VariableDefinition: ({ variable, type, defaultValue, directives }) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
145
|
+
join([
|
|
146
|
+
variable,
|
|
147
|
+
': ',
|
|
148
|
+
type,
|
|
149
|
+
wrap(' = ', defaultValue),
|
|
150
|
+
wrap(' ', join(directives, ' ')),
|
|
151
|
+
]),
|
|
45
152
|
SelectionSet: ({ selections }) => block(selections),
|
|
46
153
|
|
|
47
|
-
Field
|
|
48
|
-
const prefix = wrap('', alias, ': ')
|
|
49
|
-
let argsLine = prefix + wrap('(', join(args, ', '), ')');
|
|
50
|
-
|
|
51
|
-
if (argsLine.length > MAX_LINE_LENGTH) {
|
|
52
|
-
argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
|
|
53
|
-
}
|
|
154
|
+
Field({ alias, name, arguments: args, directives, selectionSet }) {
|
|
155
|
+
const prefix = join([wrap('', alias, ': '), name], '');
|
|
54
156
|
|
|
55
|
-
return join([
|
|
157
|
+
return join([
|
|
158
|
+
wrappedLineAndArgs(prefix, args),
|
|
159
|
+
wrap(' ', join(directives, ' ')),
|
|
160
|
+
wrap(' ', selectionSet),
|
|
161
|
+
]);
|
|
56
162
|
},
|
|
57
|
-
|
|
58
|
-
Argument: ({ name, value }) => name + ': ' + value,
|
|
163
|
+
Argument: ({ name, value }) => join([name, ': ', value]),
|
|
59
164
|
|
|
60
165
|
// Fragments
|
|
61
166
|
|
|
62
167
|
FragmentSpread: ({ name, directives }) =>
|
|
63
|
-
'...'
|
|
168
|
+
join(['...', name, wrap(' ', join(directives, ' '))]),
|
|
64
169
|
|
|
65
170
|
InlineFragment: ({ typeCondition, directives, selectionSet }) =>
|
|
66
171
|
join(
|
|
@@ -75,52 +180,74 @@ const printDocASTReducer: any = {
|
|
|
75
180
|
directives,
|
|
76
181
|
selectionSet,
|
|
77
182
|
}) =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
183
|
+
join([
|
|
184
|
+
// Note: fragment variable definitions are experimental and may be changed
|
|
185
|
+
// or removed in the future.
|
|
186
|
+
'fragment ',
|
|
187
|
+
name,
|
|
188
|
+
wrap('(', join(variableDefinitions, ', '), ')'),
|
|
189
|
+
' on ',
|
|
190
|
+
typeCondition,
|
|
191
|
+
' ',
|
|
192
|
+
wrap('', join(directives, ' '), ' '),
|
|
193
|
+
selectionSet,
|
|
194
|
+
]),
|
|
83
195
|
|
|
84
196
|
// Value
|
|
85
197
|
|
|
86
|
-
IntValue: ({ value }) => value,
|
|
87
|
-
FloatValue: ({ value }) => value,
|
|
198
|
+
IntValue: ({ value }) => new PrintBuffer(value),
|
|
199
|
+
FloatValue: ({ value }) => new PrintBuffer(value),
|
|
88
200
|
StringValue: ({ value, block: isBlockString }, key) =>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
201
|
+
new PrintBuffer(
|
|
202
|
+
isBlockString === true
|
|
203
|
+
? printBlockString(value, key === 'description' ? '' : ' ')
|
|
204
|
+
: JSON.stringify(value),
|
|
205
|
+
isBlockString === true,
|
|
206
|
+
),
|
|
207
|
+
BooleanValue: ({ value }) => new PrintBuffer(value ? 'true' : 'false'),
|
|
208
|
+
NullValue: () => new PrintBuffer('null'),
|
|
209
|
+
EnumValue: ({ value }) => new PrintBuffer(value),
|
|
210
|
+
ListValue: ({ values }) => join(['[', join(values, ', '), ']']),
|
|
211
|
+
ObjectValue: ({ fields }) => join(['{', join(fields, ', '), '}']),
|
|
212
|
+
ObjectField: ({ name, value }) => join([name, ': ', value]),
|
|
98
213
|
|
|
99
214
|
// Directive
|
|
100
215
|
|
|
101
216
|
Directive: ({ name, arguments: args }) =>
|
|
102
|
-
'@'
|
|
217
|
+
join(['@', name, wrap('(', join(args, ', '), ')')]),
|
|
103
218
|
|
|
104
219
|
// Type
|
|
105
220
|
|
|
106
221
|
NamedType: ({ name }) => name,
|
|
107
|
-
ListType: ({ type }) => '['
|
|
108
|
-
NonNullType: ({ type }) => type
|
|
222
|
+
ListType: ({ type }) => join(['[', type, ']']),
|
|
223
|
+
NonNullType: ({ type }) => join([type, '!']),
|
|
109
224
|
|
|
110
225
|
// Type System Definitions
|
|
111
226
|
|
|
112
|
-
SchemaDefinition:
|
|
113
|
-
join([
|
|
114
|
-
|
|
227
|
+
SchemaDefinition: ({ description, directives, operationTypes }) =>
|
|
228
|
+
join([
|
|
229
|
+
wrap('', description, '\n'),
|
|
230
|
+
join(['schema', join(directives, ' '), block(operationTypes)], ' '),
|
|
231
|
+
]),
|
|
115
232
|
|
|
116
|
-
OperationTypeDefinition: ({ operation, type }) =>
|
|
233
|
+
OperationTypeDefinition: ({ operation, type }) =>
|
|
234
|
+
join([operation, ': ', type]),
|
|
117
235
|
|
|
118
|
-
ScalarTypeDefinition:
|
|
119
|
-
join([
|
|
120
|
-
|
|
236
|
+
ScalarTypeDefinition: ({ description, name, directives }) =>
|
|
237
|
+
join([
|
|
238
|
+
wrap('', description, '\n'),
|
|
239
|
+
join(['scalar', name, join(directives, ' ')], ' '),
|
|
240
|
+
]),
|
|
121
241
|
|
|
122
|
-
ObjectTypeDefinition:
|
|
123
|
-
|
|
242
|
+
ObjectTypeDefinition: ({
|
|
243
|
+
description,
|
|
244
|
+
name,
|
|
245
|
+
interfaces,
|
|
246
|
+
directives,
|
|
247
|
+
fields,
|
|
248
|
+
}) =>
|
|
249
|
+
join([
|
|
250
|
+
wrap('', description, '\n'),
|
|
124
251
|
join(
|
|
125
252
|
[
|
|
126
253
|
'type',
|
|
@@ -131,29 +258,45 @@ const printDocASTReducer: any = {
|
|
|
131
258
|
],
|
|
132
259
|
' ',
|
|
133
260
|
),
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
FieldDefinition:
|
|
137
|
-
(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
261
|
+
]),
|
|
262
|
+
|
|
263
|
+
FieldDefinition: ({ description, name, arguments: args, type, directives }) =>
|
|
264
|
+
join([
|
|
265
|
+
wrap('', description, '\n'),
|
|
266
|
+
name,
|
|
267
|
+
hasMultilineItems(args)
|
|
268
|
+
? wrap('(\n', join(args, '\n').indent(), '\n)')
|
|
269
|
+
: wrap('(', join(args, ', '), ')'),
|
|
270
|
+
': ',
|
|
271
|
+
type,
|
|
144
272
|
wrap(' ', join(directives, ' ')),
|
|
145
|
-
|
|
273
|
+
]),
|
|
146
274
|
|
|
147
|
-
InputValueDefinition:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
)
|
|
275
|
+
InputValueDefinition: ({
|
|
276
|
+
description,
|
|
277
|
+
name,
|
|
278
|
+
type,
|
|
279
|
+
defaultValue,
|
|
280
|
+
directives,
|
|
281
|
+
}) =>
|
|
282
|
+
join([
|
|
283
|
+
wrap('', description, '\n'),
|
|
284
|
+
name,
|
|
285
|
+
': ',
|
|
286
|
+
type,
|
|
287
|
+
wrap(' = ', defaultValue),
|
|
288
|
+
wrap(' ', join(directives, ' ')),
|
|
289
|
+
]),
|
|
154
290
|
|
|
155
|
-
InterfaceTypeDefinition:
|
|
156
|
-
|
|
291
|
+
InterfaceTypeDefinition: ({
|
|
292
|
+
description,
|
|
293
|
+
name,
|
|
294
|
+
interfaces,
|
|
295
|
+
directives,
|
|
296
|
+
fields,
|
|
297
|
+
}) =>
|
|
298
|
+
join([
|
|
299
|
+
wrap('', description, '\n'),
|
|
157
300
|
join(
|
|
158
301
|
[
|
|
159
302
|
'interface',
|
|
@@ -164,43 +307,53 @@ const printDocASTReducer: any = {
|
|
|
164
307
|
],
|
|
165
308
|
' ',
|
|
166
309
|
),
|
|
167
|
-
|
|
310
|
+
]),
|
|
168
311
|
|
|
169
|
-
UnionTypeDefinition:
|
|
170
|
-
join(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
name,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
312
|
+
UnionTypeDefinition: ({ description, name, directives, types }) =>
|
|
313
|
+
join([
|
|
314
|
+
wrap('', description, '\n'),
|
|
315
|
+
join(
|
|
316
|
+
['union', name, join(directives, ' '), wrap('= ', join(types, ' | '))],
|
|
317
|
+
' ',
|
|
318
|
+
),
|
|
319
|
+
]),
|
|
320
|
+
|
|
321
|
+
EnumTypeDefinition: ({ description, name, directives, values }) =>
|
|
322
|
+
join([
|
|
323
|
+
wrap('', description, '\n'),
|
|
324
|
+
join(['enum', name, join(directives, ' '), block(values)], ' '),
|
|
325
|
+
]),
|
|
326
|
+
|
|
327
|
+
EnumValueDefinition: ({ description, name, directives }) =>
|
|
328
|
+
join([
|
|
329
|
+
wrap('', description, '\n'),
|
|
330
|
+
join([name, join(directives, ' ')], ' '),
|
|
331
|
+
]),
|
|
332
|
+
|
|
333
|
+
InputObjectTypeDefinition: ({ description, name, directives, fields }) =>
|
|
334
|
+
join([
|
|
335
|
+
wrap('', description, '\n'),
|
|
336
|
+
join(['input', name, join(directives, ' '), block(fields)], ' '),
|
|
337
|
+
]),
|
|
338
|
+
|
|
339
|
+
DirectiveDefinition: ({
|
|
340
|
+
description,
|
|
341
|
+
name,
|
|
342
|
+
arguments: args,
|
|
343
|
+
repeatable,
|
|
344
|
+
locations,
|
|
345
|
+
}) =>
|
|
346
|
+
join([
|
|
347
|
+
wrap('', description, '\n'),
|
|
348
|
+
'directive @',
|
|
349
|
+
name,
|
|
350
|
+
hasMultilineItems(args)
|
|
351
|
+
? wrap('(\n', join(args, '\n').indent(), '\n)')
|
|
352
|
+
: wrap('(', join(args, ', '), ')'),
|
|
353
|
+
repeatable ? ' repeatable' : '',
|
|
354
|
+
' on ',
|
|
202
355
|
join(locations, ' | '),
|
|
203
|
-
|
|
356
|
+
]),
|
|
204
357
|
|
|
205
358
|
SchemaExtension: ({ directives, operationTypes }) =>
|
|
206
359
|
join(['extend schema', join(directives, ' '), block(operationTypes)], ' '),
|
|
@@ -238,7 +391,7 @@ const printDocASTReducer: any = {
|
|
|
238
391
|
'extend union',
|
|
239
392
|
name,
|
|
240
393
|
join(directives, ' '),
|
|
241
|
-
|
|
394
|
+
wrap('= ', join(types, ' | ')),
|
|
242
395
|
],
|
|
243
396
|
' ',
|
|
244
397
|
),
|
|
@@ -250,43 +403,94 @@ const printDocASTReducer: any = {
|
|
|
250
403
|
join(['extend input', name, join(directives, ' '), block(fields)], ' '),
|
|
251
404
|
};
|
|
252
405
|
|
|
253
|
-
function addDescription(cb) {
|
|
254
|
-
return (node) => join([node.description, cb(node)], '\n');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
406
|
/**
|
|
258
407
|
* Given maybeArray, print an empty string if it is null or empty, otherwise
|
|
259
408
|
* print all items together separated by separator if provided
|
|
409
|
+
*
|
|
410
|
+
* @internal
|
|
260
411
|
*/
|
|
261
|
-
function join(
|
|
262
|
-
|
|
412
|
+
function join(
|
|
413
|
+
maybeArray: Maybe<$ReadOnlyArray<string | PrintBuffer | void>>,
|
|
414
|
+
separator = '',
|
|
415
|
+
): PrintBuffer {
|
|
416
|
+
if (maybeArray == null || maybeArray.length === 0) {
|
|
417
|
+
return EMPTY;
|
|
418
|
+
}
|
|
419
|
+
let result = EMPTY;
|
|
420
|
+
for (const item of maybeArray) {
|
|
421
|
+
if (item === undefined || item.length === 0) {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (result.length === 0) {
|
|
425
|
+
result = typeof item === 'string' ? new PrintBuffer(item) : item;
|
|
426
|
+
} else {
|
|
427
|
+
if (separator !== '') {
|
|
428
|
+
result.append(separator);
|
|
429
|
+
}
|
|
430
|
+
result.append(item);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return result;
|
|
263
434
|
}
|
|
264
435
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
436
|
+
function joinedLength(
|
|
437
|
+
array: $ReadOnlyArray<PrintBuffer>,
|
|
438
|
+
separator: string,
|
|
439
|
+
): number {
|
|
440
|
+
let length = 0;
|
|
441
|
+
for (const item of array) {
|
|
442
|
+
if (item.length !== 0) {
|
|
443
|
+
length += (length === 0 ? 0 : separator.length) + item.length;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return length;
|
|
271
447
|
}
|
|
272
448
|
|
|
273
449
|
/**
|
|
274
|
-
*
|
|
450
|
+
* Given array, print each item on its own line, wrapped in an indented `{ }` block.
|
|
451
|
+
*
|
|
452
|
+
* @internal
|
|
275
453
|
*/
|
|
276
|
-
function
|
|
277
|
-
return
|
|
278
|
-
? start + maybeString + end
|
|
279
|
-
: '';
|
|
454
|
+
function block(array: Maybe<$ReadOnlyArray<PrintBuffer | void>>): PrintBuffer {
|
|
455
|
+
return wrap('{\n', join(array, '\n').indent(), '\n}');
|
|
280
456
|
}
|
|
281
457
|
|
|
282
|
-
|
|
283
|
-
|
|
458
|
+
/**
|
|
459
|
+
* If maybeBuffer is not null or empty, then wrap with start and end, otherwise print an empty string.
|
|
460
|
+
*
|
|
461
|
+
* @internal
|
|
462
|
+
*/
|
|
463
|
+
function wrap(
|
|
464
|
+
start: string,
|
|
465
|
+
maybeBuffer: Maybe<PrintBuffer>,
|
|
466
|
+
end = '',
|
|
467
|
+
): PrintBuffer {
|
|
468
|
+
return maybeBuffer != null && maybeBuffer.length !== 0
|
|
469
|
+
? start === ''
|
|
470
|
+
? maybeBuffer.append(end)
|
|
471
|
+
: new PrintBuffer(start).append(maybeBuffer).append(end)
|
|
472
|
+
: EMPTY;
|
|
284
473
|
}
|
|
285
474
|
|
|
286
|
-
function
|
|
287
|
-
|
|
475
|
+
function hasMultilineItems(
|
|
476
|
+
maybeArray: Maybe<$ReadOnlyArray<PrintBuffer>>,
|
|
477
|
+
): boolean {
|
|
478
|
+
return (
|
|
479
|
+
maybeArray != null && maybeArray.some((result) => result.newlines !== 0)
|
|
480
|
+
);
|
|
288
481
|
}
|
|
289
482
|
|
|
290
|
-
function
|
|
291
|
-
|
|
483
|
+
function wrappedLineAndArgs(
|
|
484
|
+
prefix: PrintBuffer,
|
|
485
|
+
args: $ReadOnlyArray<PrintBuffer> | void,
|
|
486
|
+
): PrintBuffer {
|
|
487
|
+
if (args == null || args.length === 0) {
|
|
488
|
+
return prefix;
|
|
489
|
+
}
|
|
490
|
+
return join([
|
|
491
|
+
prefix,
|
|
492
|
+
prefix.length + joinedLength(args, ', ') + 2 > MAX_LINE_LENGTH
|
|
493
|
+
? wrap('(\n', join(args, '\n').indent(), '\n)')
|
|
494
|
+
: wrap('(', join(args, ', '), ')'),
|
|
495
|
+
]);
|
|
292
496
|
}
|