@graphql-tools/utils 8.7.0 → 8.8.0-alpha-b76ec274.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/cjs/AggregateError.js +25 -0
- package/cjs/Interfaces.js +31 -0
- package/cjs/addTypes.js +62 -0
- package/cjs/astFromType.js +31 -0
- package/cjs/astFromValueUntyped.js +78 -0
- package/cjs/build-operation-for-field.js +351 -0
- package/cjs/collectFields.js +98 -0
- package/cjs/comments.js +380 -0
- package/cjs/errors.js +22 -0
- package/cjs/executor.js +2 -0
- package/cjs/fields.js +115 -0
- package/cjs/filterSchema.js +66 -0
- package/cjs/fixSchemaAst.js +26 -0
- package/cjs/forEachDefaultValue.js +29 -0
- package/cjs/forEachField.js +19 -0
- package/cjs/get-directives.js +103 -0
- package/cjs/get-fields-with-directives.js +52 -0
- package/cjs/get-implementing-types.js +19 -0
- package/cjs/getArgumentValues.js +76 -0
- package/cjs/getObjectTypeFromTypeMap.js +13 -0
- package/cjs/getOperationASTFromRequest.js +16 -0
- package/cjs/getResolversFromSchema.js +73 -0
- package/cjs/getResponseKeyFromInfo.js +12 -0
- package/cjs/heal.js +177 -0
- package/cjs/helpers.js +76 -0
- package/cjs/implementsAbstractType.js +17 -0
- package/cjs/index.js +53 -0
- package/cjs/inspect.js +107 -0
- package/cjs/isAsyncIterable.js +10 -0
- package/cjs/isDocumentNode.js +8 -0
- package/cjs/loaders.js +2 -0
- package/cjs/mapAsyncIterator.js +53 -0
- package/cjs/mapSchema.js +470 -0
- package/cjs/memoize.js +189 -0
- package/cjs/mergeDeep.js +45 -0
- package/cjs/observableToAsyncIterable.js +85 -0
- package/cjs/package.json +1 -0
- package/cjs/parse-graphql-json.js +44 -0
- package/cjs/parse-graphql-sdl.js +84 -0
- package/cjs/print-schema-with-directives.js +494 -0
- package/cjs/prune.js +133 -0
- package/cjs/renameType.js +152 -0
- package/cjs/rewire.js +159 -0
- package/cjs/rootTypes.js +37 -0
- package/cjs/selectionSets.js +9 -0
- package/cjs/stub.js +68 -0
- package/cjs/transformInputValue.js +55 -0
- package/cjs/types.js +27 -0
- package/cjs/updateArgument.js +54 -0
- package/cjs/validate-documents.js +76 -0
- package/cjs/valueMatchesCriteria.js +21 -0
- package/cjs/visitResult.js +219 -0
- package/cjs/withCancel.js +56 -0
- package/esm/AggregateError.js +21 -0
- package/esm/Interfaces.js +28 -0
- package/esm/addTypes.js +58 -0
- package/esm/astFromType.js +27 -0
- package/esm/astFromValueUntyped.js +74 -0
- package/esm/build-operation-for-field.js +347 -0
- package/esm/collectFields.js +94 -0
- package/esm/comments.js +367 -0
- package/esm/errors.js +17 -0
- package/esm/executor.js +1 -0
- package/esm/fields.js +108 -0
- package/esm/filterSchema.js +62 -0
- package/esm/fixSchemaAst.js +22 -0
- package/esm/forEachDefaultValue.js +25 -0
- package/esm/forEachField.js +15 -0
- package/esm/get-directives.js +96 -0
- package/esm/get-fields-with-directives.js +48 -0
- package/esm/get-implementing-types.js +15 -0
- package/esm/getArgumentValues.js +72 -0
- package/esm/getObjectTypeFromTypeMap.js +9 -0
- package/esm/getOperationASTFromRequest.js +12 -0
- package/esm/getResolversFromSchema.js +69 -0
- package/esm/getResponseKeyFromInfo.js +8 -0
- package/esm/heal.js +172 -0
- package/esm/helpers.js +65 -0
- package/esm/implementsAbstractType.js +13 -0
- package/esm/index.js +50 -0
- package/esm/inspect.js +103 -0
- package/esm/isAsyncIterable.js +6 -0
- package/esm/isDocumentNode.js +4 -0
- package/esm/loaders.js +1 -0
- package/esm/mapAsyncIterator.js +49 -0
- package/esm/mapSchema.js +465 -0
- package/esm/memoize.js +180 -0
- package/esm/mergeDeep.js +41 -0
- package/esm/observableToAsyncIterable.js +81 -0
- package/esm/parse-graphql-json.js +40 -0
- package/esm/parse-graphql-sdl.js +78 -0
- package/esm/print-schema-with-directives.js +472 -0
- package/esm/prune.js +129 -0
- package/esm/renameType.js +148 -0
- package/esm/rewire.js +155 -0
- package/esm/rootTypes.js +33 -0
- package/esm/selectionSets.js +5 -0
- package/esm/stub.js +61 -0
- package/esm/transformInputValue.js +48 -0
- package/esm/types.js +24 -0
- package/esm/updateArgument.js +49 -0
- package/esm/validate-documents.js +70 -0
- package/esm/valueMatchesCriteria.js +17 -0
- package/esm/visitResult.js +213 -0
- package/esm/withCancel.js +51 -0
- package/package.json +31 -10
- package/{AggregateError.d.ts → typings/AggregateError.d.ts} +0 -0
- package/{Interfaces.d.ts → typings/Interfaces.d.ts} +0 -0
- package/{addTypes.d.ts → typings/addTypes.d.ts} +0 -0
- package/{astFromType.d.ts → typings/astFromType.d.ts} +0 -0
- package/{astFromValueUntyped.d.ts → typings/astFromValueUntyped.d.ts} +0 -0
- package/{build-operation-for-field.d.ts → typings/build-operation-for-field.d.ts} +0 -0
- package/{collectFields.d.ts → typings/collectFields.d.ts} +0 -0
- package/{comments.d.ts → typings/comments.d.ts} +0 -0
- package/{errors.d.ts → typings/errors.d.ts} +1 -1
- package/{executor.d.ts → typings/executor.d.ts} +1 -1
- package/{fields.d.ts → typings/fields.d.ts} +0 -0
- package/{filterSchema.d.ts → typings/filterSchema.d.ts} +1 -1
- package/{fixSchemaAst.d.ts → typings/fixSchemaAst.d.ts} +1 -1
- package/{forEachDefaultValue.d.ts → typings/forEachDefaultValue.d.ts} +1 -1
- package/{forEachField.d.ts → typings/forEachField.d.ts} +1 -1
- package/{get-directives.d.ts → typings/get-directives.d.ts} +0 -0
- package/{get-fields-with-directives.d.ts → typings/get-fields-with-directives.d.ts} +0 -0
- package/{get-implementing-types.d.ts → typings/get-implementing-types.d.ts} +0 -0
- package/{getArgumentValues.d.ts → typings/getArgumentValues.d.ts} +0 -0
- package/{getObjectTypeFromTypeMap.d.ts → typings/getObjectTypeFromTypeMap.d.ts} +1 -1
- package/{getOperationASTFromRequest.d.ts → typings/getOperationASTFromRequest.d.ts} +1 -1
- package/{getResolversFromSchema.d.ts → typings/getResolversFromSchema.d.ts} +1 -1
- package/{getResponseKeyFromInfo.d.ts → typings/getResponseKeyFromInfo.d.ts} +0 -0
- package/{heal.d.ts → typings/heal.d.ts} +0 -0
- package/{helpers.d.ts → typings/helpers.d.ts} +0 -0
- package/{implementsAbstractType.d.ts → typings/implementsAbstractType.d.ts} +1 -1
- package/typings/index.d.ts +50 -0
- package/{inspect.d.ts → typings/inspect.d.ts} +0 -0
- package/{isAsyncIterable.d.ts → typings/isAsyncIterable.d.ts} +0 -0
- package/{isDocumentNode.d.ts → typings/isDocumentNode.d.ts} +0 -0
- package/{loaders.d.ts → typings/loaders.d.ts} +1 -1
- package/{mapAsyncIterator.d.ts → typings/mapAsyncIterator.d.ts} +0 -0
- package/{mapSchema.d.ts → typings/mapSchema.d.ts} +1 -1
- package/{memoize.d.ts → typings/memoize.d.ts} +0 -0
- package/{mergeDeep.d.ts → typings/mergeDeep.d.ts} +0 -0
- package/{observableToAsyncIterable.d.ts → typings/observableToAsyncIterable.d.ts} +0 -0
- package/{parse-graphql-json.d.ts → typings/parse-graphql-json.d.ts} +2 -2
- package/{parse-graphql-sdl.d.ts → typings/parse-graphql-sdl.d.ts} +1 -1
- package/{print-schema-with-directives.d.ts → typings/print-schema-with-directives.d.ts} +1 -1
- package/{prune.d.ts → typings/prune.d.ts} +1 -1
- package/{renameType.d.ts → typings/renameType.d.ts} +0 -0
- package/{rewire.d.ts → typings/rewire.d.ts} +0 -0
- package/{rootTypes.d.ts → typings/rootTypes.d.ts} +0 -0
- package/{selectionSets.d.ts → typings/selectionSets.d.ts} +1 -1
- package/{stub.d.ts → typings/stub.d.ts} +0 -0
- package/{transformInputValue.d.ts → typings/transformInputValue.d.ts} +1 -1
- package/{types.d.ts → typings/types.d.ts} +0 -0
- package/{updateArgument.d.ts → typings/updateArgument.d.ts} +0 -0
- package/{validate-documents.d.ts → typings/validate-documents.d.ts} +1 -1
- package/{valueMatchesCriteria.d.ts → typings/valueMatchesCriteria.d.ts} +0 -0
- package/{visitResult.d.ts → typings/visitResult.d.ts} +1 -1
- package/{withCancel.d.ts → typings/withCancel.d.ts} +0 -0
- package/index.d.ts +0 -50
- package/index.js +0 -4428
- package/index.mjs +0 -4315
package/cjs/comments.js
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBlockStringIndentation = exports.dedentBlockStringValue = exports.getLeadingCommentBlock = exports.getComment = exports.getDescription = exports.printWithComments = exports.printComment = exports.pushComment = exports.collectComment = exports.resetComments = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const MAX_LINE_LENGTH = 80;
|
|
6
|
+
let commentsRegistry = {};
|
|
7
|
+
function resetComments() {
|
|
8
|
+
commentsRegistry = {};
|
|
9
|
+
}
|
|
10
|
+
exports.resetComments = resetComments;
|
|
11
|
+
function collectComment(node) {
|
|
12
|
+
var _a;
|
|
13
|
+
const entityName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;
|
|
14
|
+
if (entityName == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
pushComment(node, entityName);
|
|
18
|
+
switch (node.kind) {
|
|
19
|
+
case 'EnumTypeDefinition':
|
|
20
|
+
if (node.values) {
|
|
21
|
+
for (const value of node.values) {
|
|
22
|
+
pushComment(value, entityName, value.name.value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
case 'ObjectTypeDefinition':
|
|
27
|
+
case 'InputObjectTypeDefinition':
|
|
28
|
+
case 'InterfaceTypeDefinition':
|
|
29
|
+
if (node.fields) {
|
|
30
|
+
for (const field of node.fields) {
|
|
31
|
+
pushComment(field, entityName, field.name.value);
|
|
32
|
+
if (isFieldDefinitionNode(field) && field.arguments) {
|
|
33
|
+
for (const arg of field.arguments) {
|
|
34
|
+
pushComment(arg, entityName, field.name.value, arg.name.value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.collectComment = collectComment;
|
|
43
|
+
function pushComment(node, entity, field, argument) {
|
|
44
|
+
const comment = getComment(node);
|
|
45
|
+
if (typeof comment !== 'string' || comment.length === 0) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const keys = [entity];
|
|
49
|
+
if (field) {
|
|
50
|
+
keys.push(field);
|
|
51
|
+
if (argument) {
|
|
52
|
+
keys.push(argument);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const path = keys.join('.');
|
|
56
|
+
if (!commentsRegistry[path]) {
|
|
57
|
+
commentsRegistry[path] = [];
|
|
58
|
+
}
|
|
59
|
+
commentsRegistry[path].push(comment);
|
|
60
|
+
}
|
|
61
|
+
exports.pushComment = pushComment;
|
|
62
|
+
function printComment(comment) {
|
|
63
|
+
return '\n# ' + comment.replace(/\n/g, '\n# ');
|
|
64
|
+
}
|
|
65
|
+
exports.printComment = printComment;
|
|
66
|
+
/**
|
|
67
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
68
|
+
*
|
|
69
|
+
* This source code is licensed under the MIT license found in the
|
|
70
|
+
* LICENSE file in the root directory of this source tree.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* NOTE: ==> This file has been modified just to add comments to the printed AST
|
|
74
|
+
* This is a temp measure, we will move to using the original non modified printer.js ASAP.
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* Given maybeArray, print an empty string if it is null or empty, otherwise
|
|
78
|
+
* print all items together separated by separator if provided
|
|
79
|
+
*/
|
|
80
|
+
function join(maybeArray, separator) {
|
|
81
|
+
return maybeArray ? maybeArray.filter(x => x).join(separator || '') : '';
|
|
82
|
+
}
|
|
83
|
+
function hasMultilineItems(maybeArray) {
|
|
84
|
+
var _a;
|
|
85
|
+
return (_a = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.some(str => str.includes('\n'))) !== null && _a !== void 0 ? _a : false;
|
|
86
|
+
}
|
|
87
|
+
function addDescription(cb) {
|
|
88
|
+
return (node, _key, _parent, path, ancestors) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const keys = [];
|
|
91
|
+
const parent = path.reduce((prev, key) => {
|
|
92
|
+
if (['fields', 'arguments', 'values'].includes(key) && prev.name) {
|
|
93
|
+
keys.push(prev.name.value);
|
|
94
|
+
}
|
|
95
|
+
return prev[key];
|
|
96
|
+
}, ancestors[0]);
|
|
97
|
+
const key = [...keys, (_a = parent === null || parent === void 0 ? void 0 : parent.name) === null || _a === void 0 ? void 0 : _a.value].filter(Boolean).join('.');
|
|
98
|
+
const items = [];
|
|
99
|
+
if (node.kind.includes('Definition') && commentsRegistry[key]) {
|
|
100
|
+
items.push(...commentsRegistry[key]);
|
|
101
|
+
}
|
|
102
|
+
return join([...items.map(printComment), node.description, cb(node, _key, _parent, path, ancestors)], '\n');
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function indent(maybeString) {
|
|
106
|
+
return maybeString && ` ${maybeString.replace(/\n/g, '\n ')}`;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Given array, print each item on its own line, wrapped in an
|
|
110
|
+
* indented "{ }" block.
|
|
111
|
+
*/
|
|
112
|
+
function block(array) {
|
|
113
|
+
return array && array.length !== 0 ? `{\n${indent(join(array, '\n'))}\n}` : '';
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* If maybeString is not null or empty, then wrap with start and end, otherwise
|
|
117
|
+
* print an empty string.
|
|
118
|
+
*/
|
|
119
|
+
function wrap(start, maybeString, end) {
|
|
120
|
+
return maybeString ? start + maybeString + (end || '') : '';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Print a block string in the indented block form by adding a leading and
|
|
124
|
+
* trailing blank line. However, if a block string starts with whitespace and is
|
|
125
|
+
* a single-line, adding a leading blank line would strip that whitespace.
|
|
126
|
+
*/
|
|
127
|
+
function printBlockString(value, isDescription = false) {
|
|
128
|
+
const escaped = value.replace(/"""/g, '\\"""');
|
|
129
|
+
return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1
|
|
130
|
+
? `"""${escaped.replace(/"$/, '"\n')}"""`
|
|
131
|
+
: `"""\n${isDescription ? escaped : indent(escaped)}\n"""`;
|
|
132
|
+
}
|
|
133
|
+
const printDocASTReducer = {
|
|
134
|
+
Name: { leave: node => node.value },
|
|
135
|
+
Variable: { leave: node => '$' + node.name },
|
|
136
|
+
// Document
|
|
137
|
+
Document: {
|
|
138
|
+
leave: node => join(node.definitions, '\n\n'),
|
|
139
|
+
},
|
|
140
|
+
OperationDefinition: {
|
|
141
|
+
leave: node => {
|
|
142
|
+
const varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
|
|
143
|
+
const prefix = join([node.operation, join([node.name, varDefs]), join(node.directives, ' ')], ' ');
|
|
144
|
+
// the query short form.
|
|
145
|
+
return prefix + ' ' + node.selectionSet;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
VariableDefinition: {
|
|
149
|
+
leave: ({ variable, type, defaultValue, directives }) => variable + ': ' + type + wrap(' = ', defaultValue) + wrap(' ', join(directives, ' ')),
|
|
150
|
+
},
|
|
151
|
+
SelectionSet: { leave: ({ selections }) => block(selections) },
|
|
152
|
+
Field: {
|
|
153
|
+
leave({ alias, name, arguments: args, directives, selectionSet }) {
|
|
154
|
+
const prefix = wrap('', alias, ': ') + name;
|
|
155
|
+
let argsLine = prefix + wrap('(', join(args, ', '), ')');
|
|
156
|
+
if (argsLine.length > MAX_LINE_LENGTH) {
|
|
157
|
+
argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
|
|
158
|
+
}
|
|
159
|
+
return join([argsLine, join(directives, ' '), selectionSet], ' ');
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
Argument: { leave: ({ name, value }) => name + ': ' + value },
|
|
163
|
+
// Fragments
|
|
164
|
+
FragmentSpread: {
|
|
165
|
+
leave: ({ name, directives }) => '...' + name + wrap(' ', join(directives, ' ')),
|
|
166
|
+
},
|
|
167
|
+
InlineFragment: {
|
|
168
|
+
leave: ({ typeCondition, directives, selectionSet }) => join(['...', wrap('on ', typeCondition), join(directives, ' '), selectionSet], ' '),
|
|
169
|
+
},
|
|
170
|
+
FragmentDefinition: {
|
|
171
|
+
leave: ({ name, typeCondition, variableDefinitions, directives, selectionSet }) =>
|
|
172
|
+
// Note: fragment variable definitions are experimental and may be changed
|
|
173
|
+
// or removed in the future.
|
|
174
|
+
`fragment ${name}${wrap('(', join(variableDefinitions, ', '), ')')} ` +
|
|
175
|
+
`on ${typeCondition} ${wrap('', join(directives, ' '), ' ')}` +
|
|
176
|
+
selectionSet,
|
|
177
|
+
},
|
|
178
|
+
// Value
|
|
179
|
+
IntValue: { leave: ({ value }) => value },
|
|
180
|
+
FloatValue: { leave: ({ value }) => value },
|
|
181
|
+
StringValue: {
|
|
182
|
+
leave: ({ value, block: isBlockString }) => {
|
|
183
|
+
if (isBlockString) {
|
|
184
|
+
return printBlockString(value);
|
|
185
|
+
}
|
|
186
|
+
return JSON.stringify(value);
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
BooleanValue: { leave: ({ value }) => (value ? 'true' : 'false') },
|
|
190
|
+
NullValue: { leave: () => 'null' },
|
|
191
|
+
EnumValue: { leave: ({ value }) => value },
|
|
192
|
+
ListValue: { leave: ({ values }) => '[' + join(values, ', ') + ']' },
|
|
193
|
+
ObjectValue: { leave: ({ fields }) => '{' + join(fields, ', ') + '}' },
|
|
194
|
+
ObjectField: { leave: ({ name, value }) => name + ': ' + value },
|
|
195
|
+
// Directive
|
|
196
|
+
Directive: {
|
|
197
|
+
leave: ({ name, arguments: args }) => '@' + name + wrap('(', join(args, ', '), ')'),
|
|
198
|
+
},
|
|
199
|
+
// Type
|
|
200
|
+
NamedType: { leave: ({ name }) => name },
|
|
201
|
+
ListType: { leave: ({ type }) => '[' + type + ']' },
|
|
202
|
+
NonNullType: { leave: ({ type }) => type + '!' },
|
|
203
|
+
// Type System Definitions
|
|
204
|
+
SchemaDefinition: {
|
|
205
|
+
leave: ({ directives, operationTypes }) => join(['schema', join(directives, ' '), block(operationTypes)], ' '),
|
|
206
|
+
},
|
|
207
|
+
OperationTypeDefinition: {
|
|
208
|
+
leave: ({ operation, type }) => operation + ': ' + type,
|
|
209
|
+
},
|
|
210
|
+
ScalarTypeDefinition: {
|
|
211
|
+
leave: ({ name, directives }) => join(['scalar', name, join(directives, ' ')], ' '),
|
|
212
|
+
},
|
|
213
|
+
ObjectTypeDefinition: {
|
|
214
|
+
leave: ({ name, interfaces, directives, fields }) => join(['type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' '),
|
|
215
|
+
},
|
|
216
|
+
FieldDefinition: {
|
|
217
|
+
leave: ({ name, arguments: args, type, directives }) => name +
|
|
218
|
+
(hasMultilineItems(args)
|
|
219
|
+
? wrap('(\n', indent(join(args, '\n')), '\n)')
|
|
220
|
+
: wrap('(', join(args, ', '), ')')) +
|
|
221
|
+
': ' +
|
|
222
|
+
type +
|
|
223
|
+
wrap(' ', join(directives, ' ')),
|
|
224
|
+
},
|
|
225
|
+
InputValueDefinition: {
|
|
226
|
+
leave: ({ name, type, defaultValue, directives }) => join([name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')], ' '),
|
|
227
|
+
},
|
|
228
|
+
InterfaceTypeDefinition: {
|
|
229
|
+
leave: ({ name, interfaces, directives, fields }) => join(['interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' '),
|
|
230
|
+
},
|
|
231
|
+
UnionTypeDefinition: {
|
|
232
|
+
leave: ({ name, directives, types }) => join(['union', name, join(directives, ' '), wrap('= ', join(types, ' | '))], ' '),
|
|
233
|
+
},
|
|
234
|
+
EnumTypeDefinition: {
|
|
235
|
+
leave: ({ name, directives, values }) => join(['enum', name, join(directives, ' '), block(values)], ' '),
|
|
236
|
+
},
|
|
237
|
+
EnumValueDefinition: {
|
|
238
|
+
leave: ({ name, directives }) => join([name, join(directives, ' ')], ' '),
|
|
239
|
+
},
|
|
240
|
+
InputObjectTypeDefinition: {
|
|
241
|
+
leave: ({ name, directives, fields }) => join(['input', name, join(directives, ' '), block(fields)], ' '),
|
|
242
|
+
},
|
|
243
|
+
DirectiveDefinition: {
|
|
244
|
+
leave: ({ name, arguments: args, repeatable, locations }) => 'directive @' +
|
|
245
|
+
name +
|
|
246
|
+
(hasMultilineItems(args)
|
|
247
|
+
? wrap('(\n', indent(join(args, '\n')), '\n)')
|
|
248
|
+
: wrap('(', join(args, ', '), ')')) +
|
|
249
|
+
(repeatable ? ' repeatable' : '') +
|
|
250
|
+
' on ' +
|
|
251
|
+
join(locations, ' | '),
|
|
252
|
+
},
|
|
253
|
+
SchemaExtension: {
|
|
254
|
+
leave: ({ directives, operationTypes }) => join(['extend schema', join(directives, ' '), block(operationTypes)], ' '),
|
|
255
|
+
},
|
|
256
|
+
ScalarTypeExtension: {
|
|
257
|
+
leave: ({ name, directives }) => join(['extend scalar', name, join(directives, ' ')], ' '),
|
|
258
|
+
},
|
|
259
|
+
ObjectTypeExtension: {
|
|
260
|
+
leave: ({ name, interfaces, directives, fields }) => join(['extend type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' '),
|
|
261
|
+
},
|
|
262
|
+
InterfaceTypeExtension: {
|
|
263
|
+
leave: ({ name, interfaces, directives, fields }) => join(['extend interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' '),
|
|
264
|
+
},
|
|
265
|
+
UnionTypeExtension: {
|
|
266
|
+
leave: ({ name, directives, types }) => join(['extend union', name, join(directives, ' '), wrap('= ', join(types, ' | '))], ' '),
|
|
267
|
+
},
|
|
268
|
+
EnumTypeExtension: {
|
|
269
|
+
leave: ({ name, directives, values }) => join(['extend enum', name, join(directives, ' '), block(values)], ' '),
|
|
270
|
+
},
|
|
271
|
+
InputObjectTypeExtension: {
|
|
272
|
+
leave: ({ name, directives, fields }) => join(['extend input', name, join(directives, ' '), block(fields)], ' '),
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
const printDocASTReducerWithComments = Object.keys(printDocASTReducer).reduce((prev, key) => ({
|
|
276
|
+
...prev,
|
|
277
|
+
[key]: {
|
|
278
|
+
leave: addDescription(printDocASTReducer[key].leave),
|
|
279
|
+
},
|
|
280
|
+
}), {});
|
|
281
|
+
/**
|
|
282
|
+
* Converts an AST into a string, using one set of reasonable
|
|
283
|
+
* formatting rules.
|
|
284
|
+
*/
|
|
285
|
+
function printWithComments(ast) {
|
|
286
|
+
return (0, graphql_1.visit)(ast, printDocASTReducerWithComments);
|
|
287
|
+
}
|
|
288
|
+
exports.printWithComments = printWithComments;
|
|
289
|
+
function isFieldDefinitionNode(node) {
|
|
290
|
+
return node.kind === 'FieldDefinition';
|
|
291
|
+
}
|
|
292
|
+
// graphql < v13 and > v15 does not export getDescription
|
|
293
|
+
function getDescription(node, options) {
|
|
294
|
+
if (node.description != null) {
|
|
295
|
+
return node.description.value;
|
|
296
|
+
}
|
|
297
|
+
if (options === null || options === void 0 ? void 0 : options.commentDescriptions) {
|
|
298
|
+
return getComment(node);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.getDescription = getDescription;
|
|
302
|
+
function getComment(node) {
|
|
303
|
+
const rawValue = getLeadingCommentBlock(node);
|
|
304
|
+
if (rawValue !== undefined) {
|
|
305
|
+
return dedentBlockStringValue(`\n${rawValue}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
exports.getComment = getComment;
|
|
309
|
+
function getLeadingCommentBlock(node) {
|
|
310
|
+
const loc = node.loc;
|
|
311
|
+
if (!loc) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const comments = [];
|
|
315
|
+
let token = loc.startToken.prev;
|
|
316
|
+
while (token != null &&
|
|
317
|
+
token.kind === graphql_1.TokenKind.COMMENT &&
|
|
318
|
+
token.next != null &&
|
|
319
|
+
token.prev != null &&
|
|
320
|
+
token.line + 1 === token.next.line &&
|
|
321
|
+
token.line !== token.prev.line) {
|
|
322
|
+
const value = String(token.value);
|
|
323
|
+
comments.push(value);
|
|
324
|
+
token = token.prev;
|
|
325
|
+
}
|
|
326
|
+
return comments.length > 0 ? comments.reverse().join('\n') : undefined;
|
|
327
|
+
}
|
|
328
|
+
exports.getLeadingCommentBlock = getLeadingCommentBlock;
|
|
329
|
+
function dedentBlockStringValue(rawString) {
|
|
330
|
+
// Expand a block string's raw value into independent lines.
|
|
331
|
+
const lines = rawString.split(/\r\n|[\n\r]/g);
|
|
332
|
+
// Remove common indentation from all lines but first.
|
|
333
|
+
const commonIndent = getBlockStringIndentation(lines);
|
|
334
|
+
if (commonIndent !== 0) {
|
|
335
|
+
for (let i = 1; i < lines.length; i++) {
|
|
336
|
+
lines[i] = lines[i].slice(commonIndent);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// Remove leading and trailing blank lines.
|
|
340
|
+
while (lines.length > 0 && isBlank(lines[0])) {
|
|
341
|
+
lines.shift();
|
|
342
|
+
}
|
|
343
|
+
while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
|
|
344
|
+
lines.pop();
|
|
345
|
+
}
|
|
346
|
+
// Return a string of the lines joined with U+000A.
|
|
347
|
+
return lines.join('\n');
|
|
348
|
+
}
|
|
349
|
+
exports.dedentBlockStringValue = dedentBlockStringValue;
|
|
350
|
+
/**
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
function getBlockStringIndentation(lines) {
|
|
354
|
+
let commonIndent = null;
|
|
355
|
+
for (let i = 1; i < lines.length; i++) {
|
|
356
|
+
const line = lines[i];
|
|
357
|
+
const indent = leadingWhitespace(line);
|
|
358
|
+
if (indent === line.length) {
|
|
359
|
+
continue; // skip empty lines
|
|
360
|
+
}
|
|
361
|
+
if (commonIndent === null || indent < commonIndent) {
|
|
362
|
+
commonIndent = indent;
|
|
363
|
+
if (commonIndent === 0) {
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return commonIndent === null ? 0 : commonIndent;
|
|
369
|
+
}
|
|
370
|
+
exports.getBlockStringIndentation = getBlockStringIndentation;
|
|
371
|
+
function leadingWhitespace(str) {
|
|
372
|
+
let i = 0;
|
|
373
|
+
while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
|
|
374
|
+
i++;
|
|
375
|
+
}
|
|
376
|
+
return i;
|
|
377
|
+
}
|
|
378
|
+
function isBlank(str) {
|
|
379
|
+
return leadingWhitespace(str) === str.length;
|
|
380
|
+
}
|
package/cjs/errors.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.relocatedError = exports.createGraphQLError = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function createGraphQLError(message, options) {
|
|
6
|
+
if (graphql_1.versionInfo.major >= 17) {
|
|
7
|
+
return new graphql_1.GraphQLError(message, options);
|
|
8
|
+
}
|
|
9
|
+
return new graphql_1.GraphQLError(message, options === null || options === void 0 ? void 0 : options.nodes, options === null || options === void 0 ? void 0 : options.source, options === null || options === void 0 ? void 0 : options.positions, options === null || options === void 0 ? void 0 : options.path, options === null || options === void 0 ? void 0 : options.originalError, options === null || options === void 0 ? void 0 : options.extensions);
|
|
10
|
+
}
|
|
11
|
+
exports.createGraphQLError = createGraphQLError;
|
|
12
|
+
function relocatedError(originalError, path) {
|
|
13
|
+
return createGraphQLError(originalError.message, {
|
|
14
|
+
nodes: originalError.nodes,
|
|
15
|
+
source: originalError.source,
|
|
16
|
+
positions: originalError.positions,
|
|
17
|
+
path: path == null ? originalError.path : path,
|
|
18
|
+
originalError,
|
|
19
|
+
extensions: originalError.extensions,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.relocatedError = relocatedError;
|
package/cjs/executor.js
ADDED
package/cjs/fields.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modifyObjectFields = exports.selectObjectFields = exports.removeObjectFields = exports.appendObjectFields = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const Interfaces_js_1 = require("./Interfaces.js");
|
|
6
|
+
const mapSchema_js_1 = require("./mapSchema.js");
|
|
7
|
+
const addTypes_js_1 = require("./addTypes.js");
|
|
8
|
+
function appendObjectFields(schema, typeName, additionalFields) {
|
|
9
|
+
if (schema.getType(typeName) == null) {
|
|
10
|
+
return (0, addTypes_js_1.addTypes)(schema, [
|
|
11
|
+
new graphql_1.GraphQLObjectType({
|
|
12
|
+
name: typeName,
|
|
13
|
+
fields: additionalFields,
|
|
14
|
+
}),
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
return (0, mapSchema_js_1.mapSchema)(schema, {
|
|
18
|
+
[Interfaces_js_1.MapperKind.OBJECT_TYPE]: type => {
|
|
19
|
+
if (type.name === typeName) {
|
|
20
|
+
const config = type.toConfig();
|
|
21
|
+
const originalFieldConfigMap = config.fields;
|
|
22
|
+
const newFieldConfigMap = {};
|
|
23
|
+
for (const fieldName in originalFieldConfigMap) {
|
|
24
|
+
newFieldConfigMap[fieldName] = originalFieldConfigMap[fieldName];
|
|
25
|
+
}
|
|
26
|
+
for (const fieldName in additionalFields) {
|
|
27
|
+
newFieldConfigMap[fieldName] = additionalFields[fieldName];
|
|
28
|
+
}
|
|
29
|
+
return (0, mapSchema_js_1.correctASTNodes)(new graphql_1.GraphQLObjectType({
|
|
30
|
+
...config,
|
|
31
|
+
fields: newFieldConfigMap,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.appendObjectFields = appendObjectFields;
|
|
38
|
+
function removeObjectFields(schema, typeName, testFn) {
|
|
39
|
+
const removedFields = {};
|
|
40
|
+
const newSchema = (0, mapSchema_js_1.mapSchema)(schema, {
|
|
41
|
+
[Interfaces_js_1.MapperKind.OBJECT_TYPE]: type => {
|
|
42
|
+
if (type.name === typeName) {
|
|
43
|
+
const config = type.toConfig();
|
|
44
|
+
const originalFieldConfigMap = config.fields;
|
|
45
|
+
const newFieldConfigMap = {};
|
|
46
|
+
for (const fieldName in originalFieldConfigMap) {
|
|
47
|
+
const originalFieldConfig = originalFieldConfigMap[fieldName];
|
|
48
|
+
if (testFn(fieldName, originalFieldConfig)) {
|
|
49
|
+
removedFields[fieldName] = originalFieldConfig;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
newFieldConfigMap[fieldName] = originalFieldConfig;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return (0, mapSchema_js_1.correctASTNodes)(new graphql_1.GraphQLObjectType({
|
|
56
|
+
...config,
|
|
57
|
+
fields: newFieldConfigMap,
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
return [newSchema, removedFields];
|
|
63
|
+
}
|
|
64
|
+
exports.removeObjectFields = removeObjectFields;
|
|
65
|
+
function selectObjectFields(schema, typeName, testFn) {
|
|
66
|
+
const selectedFields = {};
|
|
67
|
+
(0, mapSchema_js_1.mapSchema)(schema, {
|
|
68
|
+
[Interfaces_js_1.MapperKind.OBJECT_TYPE]: type => {
|
|
69
|
+
if (type.name === typeName) {
|
|
70
|
+
const config = type.toConfig();
|
|
71
|
+
const originalFieldConfigMap = config.fields;
|
|
72
|
+
for (const fieldName in originalFieldConfigMap) {
|
|
73
|
+
const originalFieldConfig = originalFieldConfigMap[fieldName];
|
|
74
|
+
if (testFn(fieldName, originalFieldConfig)) {
|
|
75
|
+
selectedFields[fieldName] = originalFieldConfig;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
return selectedFields;
|
|
83
|
+
}
|
|
84
|
+
exports.selectObjectFields = selectObjectFields;
|
|
85
|
+
function modifyObjectFields(schema, typeName, testFn, newFields) {
|
|
86
|
+
const removedFields = {};
|
|
87
|
+
const newSchema = (0, mapSchema_js_1.mapSchema)(schema, {
|
|
88
|
+
[Interfaces_js_1.MapperKind.OBJECT_TYPE]: type => {
|
|
89
|
+
if (type.name === typeName) {
|
|
90
|
+
const config = type.toConfig();
|
|
91
|
+
const originalFieldConfigMap = config.fields;
|
|
92
|
+
const newFieldConfigMap = {};
|
|
93
|
+
for (const fieldName in originalFieldConfigMap) {
|
|
94
|
+
const originalFieldConfig = originalFieldConfigMap[fieldName];
|
|
95
|
+
if (testFn(fieldName, originalFieldConfig)) {
|
|
96
|
+
removedFields[fieldName] = originalFieldConfig;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
newFieldConfigMap[fieldName] = originalFieldConfig;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const fieldName in newFields) {
|
|
103
|
+
const fieldConfig = newFields[fieldName];
|
|
104
|
+
newFieldConfigMap[fieldName] = fieldConfig;
|
|
105
|
+
}
|
|
106
|
+
return (0, mapSchema_js_1.correctASTNodes)(new graphql_1.GraphQLObjectType({
|
|
107
|
+
...config,
|
|
108
|
+
fields: newFieldConfigMap,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return [newSchema, removedFields];
|
|
114
|
+
}
|
|
115
|
+
exports.modifyObjectFields = modifyObjectFields;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterSchema = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const Interfaces_js_1 = require("./Interfaces.js");
|
|
6
|
+
const mapSchema_js_1 = require("./mapSchema.js");
|
|
7
|
+
function filterSchema({ schema, typeFilter = () => true, fieldFilter = undefined, rootFieldFilter = undefined, objectFieldFilter = undefined, interfaceFieldFilter = undefined, inputObjectFieldFilter = undefined, argumentFilter = undefined, }) {
|
|
8
|
+
const filteredSchema = (0, mapSchema_js_1.mapSchema)(schema, {
|
|
9
|
+
[Interfaces_js_1.MapperKind.QUERY]: (type) => filterRootFields(type, 'Query', rootFieldFilter, argumentFilter),
|
|
10
|
+
[Interfaces_js_1.MapperKind.MUTATION]: (type) => filterRootFields(type, 'Mutation', rootFieldFilter, argumentFilter),
|
|
11
|
+
[Interfaces_js_1.MapperKind.SUBSCRIPTION]: (type) => filterRootFields(type, 'Subscription', rootFieldFilter, argumentFilter),
|
|
12
|
+
[Interfaces_js_1.MapperKind.OBJECT_TYPE]: (type) => typeFilter(type.name, type)
|
|
13
|
+
? filterElementFields(graphql_1.GraphQLObjectType, type, objectFieldFilter || fieldFilter, argumentFilter)
|
|
14
|
+
: null,
|
|
15
|
+
[Interfaces_js_1.MapperKind.INTERFACE_TYPE]: (type) => typeFilter(type.name, type)
|
|
16
|
+
? filterElementFields(graphql_1.GraphQLInterfaceType, type, interfaceFieldFilter || fieldFilter, argumentFilter)
|
|
17
|
+
: null,
|
|
18
|
+
[Interfaces_js_1.MapperKind.INPUT_OBJECT_TYPE]: (type) => typeFilter(type.name, type)
|
|
19
|
+
? filterElementFields(graphql_1.GraphQLInputObjectType, type, inputObjectFieldFilter || fieldFilter)
|
|
20
|
+
: null,
|
|
21
|
+
[Interfaces_js_1.MapperKind.UNION_TYPE]: (type) => (typeFilter(type.name, type) ? undefined : null),
|
|
22
|
+
[Interfaces_js_1.MapperKind.ENUM_TYPE]: (type) => (typeFilter(type.name, type) ? undefined : null),
|
|
23
|
+
[Interfaces_js_1.MapperKind.SCALAR_TYPE]: (type) => (typeFilter(type.name, type) ? undefined : null),
|
|
24
|
+
});
|
|
25
|
+
return filteredSchema;
|
|
26
|
+
}
|
|
27
|
+
exports.filterSchema = filterSchema;
|
|
28
|
+
function filterRootFields(type, operation, rootFieldFilter, argumentFilter) {
|
|
29
|
+
if (rootFieldFilter || argumentFilter) {
|
|
30
|
+
const config = type.toConfig();
|
|
31
|
+
for (const fieldName in config.fields) {
|
|
32
|
+
const field = config.fields[fieldName];
|
|
33
|
+
if (rootFieldFilter && !rootFieldFilter(operation, fieldName, config.fields[fieldName])) {
|
|
34
|
+
delete config.fields[fieldName];
|
|
35
|
+
}
|
|
36
|
+
else if (argumentFilter && field.args) {
|
|
37
|
+
for (const argName in field.args) {
|
|
38
|
+
if (!argumentFilter(operation, fieldName, argName, field.args[argName])) {
|
|
39
|
+
delete field.args[argName];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new graphql_1.GraphQLObjectType(config);
|
|
45
|
+
}
|
|
46
|
+
return type;
|
|
47
|
+
}
|
|
48
|
+
function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilter) {
|
|
49
|
+
if (fieldFilter || argumentFilter) {
|
|
50
|
+
const config = type.toConfig();
|
|
51
|
+
for (const fieldName in config.fields) {
|
|
52
|
+
const field = config.fields[fieldName];
|
|
53
|
+
if (fieldFilter && !fieldFilter(type.name, fieldName, config.fields[fieldName])) {
|
|
54
|
+
delete config.fields[fieldName];
|
|
55
|
+
}
|
|
56
|
+
else if (argumentFilter && 'args' in field) {
|
|
57
|
+
for (const argName in field.args) {
|
|
58
|
+
if (!argumentFilter(type.name, fieldName, argName, field.args[argName])) {
|
|
59
|
+
delete field.args[argName];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new ElementConstructor(config);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixSchemaAst = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const print_schema_with_directives_js_1 = require("./print-schema-with-directives.js");
|
|
6
|
+
function buildFixedSchema(schema, options) {
|
|
7
|
+
const document = (0, print_schema_with_directives_js_1.getDocumentNodeFromSchema)(schema);
|
|
8
|
+
return (0, graphql_1.buildASTSchema)(document, {
|
|
9
|
+
...(options || {}),
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function fixSchemaAst(schema, options) {
|
|
13
|
+
// eslint-disable-next-line no-undef-init
|
|
14
|
+
let schemaWithValidAst = undefined;
|
|
15
|
+
if (!schema.astNode || !schema.extensionASTNodes) {
|
|
16
|
+
schemaWithValidAst = buildFixedSchema(schema, options);
|
|
17
|
+
}
|
|
18
|
+
if (!schema.astNode && (schemaWithValidAst === null || schemaWithValidAst === void 0 ? void 0 : schemaWithValidAst.astNode)) {
|
|
19
|
+
schema.astNode = schemaWithValidAst.astNode;
|
|
20
|
+
}
|
|
21
|
+
if (!schema.extensionASTNodes && (schemaWithValidAst === null || schemaWithValidAst === void 0 ? void 0 : schemaWithValidAst.astNode)) {
|
|
22
|
+
schema.extensionASTNodes = schemaWithValidAst.extensionASTNodes;
|
|
23
|
+
}
|
|
24
|
+
return schema;
|
|
25
|
+
}
|
|
26
|
+
exports.fixSchemaAst = fixSchemaAst;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forEachDefaultValue = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function forEachDefaultValue(schema, fn) {
|
|
6
|
+
const typeMap = schema.getTypeMap();
|
|
7
|
+
for (const typeName in typeMap) {
|
|
8
|
+
const type = typeMap[typeName];
|
|
9
|
+
if (!(0, graphql_1.getNamedType)(type).name.startsWith('__')) {
|
|
10
|
+
if ((0, graphql_1.isObjectType)(type)) {
|
|
11
|
+
const fields = type.getFields();
|
|
12
|
+
for (const fieldName in fields) {
|
|
13
|
+
const field = fields[fieldName];
|
|
14
|
+
for (const arg of field.args) {
|
|
15
|
+
arg.defaultValue = fn(arg.type, arg.defaultValue);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if ((0, graphql_1.isInputObjectType)(type)) {
|
|
20
|
+
const fields = type.getFields();
|
|
21
|
+
for (const fieldName in fields) {
|
|
22
|
+
const field = fields[fieldName];
|
|
23
|
+
field.defaultValue = fn(field.type, field.defaultValue);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.forEachDefaultValue = forEachDefaultValue;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forEachField = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function forEachField(schema, fn) {
|
|
6
|
+
const typeMap = schema.getTypeMap();
|
|
7
|
+
for (const typeName in typeMap) {
|
|
8
|
+
const type = typeMap[typeName];
|
|
9
|
+
// TODO: maybe have an option to include these?
|
|
10
|
+
if (!(0, graphql_1.getNamedType)(type).name.startsWith('__') && (0, graphql_1.isObjectType)(type)) {
|
|
11
|
+
const fields = type.getFields();
|
|
12
|
+
for (const fieldName in fields) {
|
|
13
|
+
const field = fields[fieldName];
|
|
14
|
+
fn(field, typeName, fieldName);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.forEachField = forEachField;
|