@graphql-tools/utils 8.7.0 → 8.8.0-alpha-6c480b2d.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 +229 -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 +223 -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/esm/memoize.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export function memoize1(fn) {
|
|
2
|
+
const memoize1cache = new WeakMap();
|
|
3
|
+
return function memoized(a1) {
|
|
4
|
+
const cachedValue = memoize1cache.get(a1);
|
|
5
|
+
if (cachedValue === undefined) {
|
|
6
|
+
const newValue = fn(a1);
|
|
7
|
+
memoize1cache.set(a1, newValue);
|
|
8
|
+
return newValue;
|
|
9
|
+
}
|
|
10
|
+
return cachedValue;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function memoize2(fn) {
|
|
14
|
+
const memoize2cache = new WeakMap();
|
|
15
|
+
return function memoized(a1, a2) {
|
|
16
|
+
let cache2 = memoize2cache.get(a1);
|
|
17
|
+
if (!cache2) {
|
|
18
|
+
cache2 = new WeakMap();
|
|
19
|
+
memoize2cache.set(a1, cache2);
|
|
20
|
+
const newValue = fn(a1, a2);
|
|
21
|
+
cache2.set(a2, newValue);
|
|
22
|
+
return newValue;
|
|
23
|
+
}
|
|
24
|
+
const cachedValue = cache2.get(a2);
|
|
25
|
+
if (cachedValue === undefined) {
|
|
26
|
+
const newValue = fn(a1, a2);
|
|
27
|
+
cache2.set(a2, newValue);
|
|
28
|
+
return newValue;
|
|
29
|
+
}
|
|
30
|
+
return cachedValue;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function memoize3(fn) {
|
|
34
|
+
const memoize3Cache = new WeakMap();
|
|
35
|
+
return function memoized(a1, a2, a3) {
|
|
36
|
+
let cache2 = memoize3Cache.get(a1);
|
|
37
|
+
if (!cache2) {
|
|
38
|
+
cache2 = new WeakMap();
|
|
39
|
+
memoize3Cache.set(a1, cache2);
|
|
40
|
+
const cache3 = new WeakMap();
|
|
41
|
+
cache2.set(a2, cache3);
|
|
42
|
+
const newValue = fn(a1, a2, a3);
|
|
43
|
+
cache3.set(a3, newValue);
|
|
44
|
+
return newValue;
|
|
45
|
+
}
|
|
46
|
+
let cache3 = cache2.get(a2);
|
|
47
|
+
if (!cache3) {
|
|
48
|
+
cache3 = new WeakMap();
|
|
49
|
+
cache2.set(a2, cache3);
|
|
50
|
+
const newValue = fn(a1, a2, a3);
|
|
51
|
+
cache3.set(a3, newValue);
|
|
52
|
+
return newValue;
|
|
53
|
+
}
|
|
54
|
+
const cachedValue = cache3.get(a3);
|
|
55
|
+
if (cachedValue === undefined) {
|
|
56
|
+
const newValue = fn(a1, a2, a3);
|
|
57
|
+
cache3.set(a3, newValue);
|
|
58
|
+
return newValue;
|
|
59
|
+
}
|
|
60
|
+
return cachedValue;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function memoize4(fn) {
|
|
64
|
+
const memoize4Cache = new WeakMap();
|
|
65
|
+
return function memoized(a1, a2, a3, a4) {
|
|
66
|
+
let cache2 = memoize4Cache.get(a1);
|
|
67
|
+
if (!cache2) {
|
|
68
|
+
cache2 = new WeakMap();
|
|
69
|
+
memoize4Cache.set(a1, cache2);
|
|
70
|
+
const cache3 = new WeakMap();
|
|
71
|
+
cache2.set(a2, cache3);
|
|
72
|
+
const cache4 = new WeakMap();
|
|
73
|
+
cache3.set(a3, cache4);
|
|
74
|
+
const newValue = fn(a1, a2, a3, a4);
|
|
75
|
+
cache4.set(a4, newValue);
|
|
76
|
+
return newValue;
|
|
77
|
+
}
|
|
78
|
+
let cache3 = cache2.get(a2);
|
|
79
|
+
if (!cache3) {
|
|
80
|
+
cache3 = new WeakMap();
|
|
81
|
+
cache2.set(a2, cache3);
|
|
82
|
+
const cache4 = new WeakMap();
|
|
83
|
+
cache3.set(a3, cache4);
|
|
84
|
+
const newValue = fn(a1, a2, a3, a4);
|
|
85
|
+
cache4.set(a4, newValue);
|
|
86
|
+
return newValue;
|
|
87
|
+
}
|
|
88
|
+
const cache4 = cache3.get(a3);
|
|
89
|
+
if (!cache4) {
|
|
90
|
+
const cache4 = new WeakMap();
|
|
91
|
+
cache3.set(a3, cache4);
|
|
92
|
+
const newValue = fn(a1, a2, a3, a4);
|
|
93
|
+
cache4.set(a4, newValue);
|
|
94
|
+
return newValue;
|
|
95
|
+
}
|
|
96
|
+
const cachedValue = cache4.get(a4);
|
|
97
|
+
if (cachedValue === undefined) {
|
|
98
|
+
const newValue = fn(a1, a2, a3, a4);
|
|
99
|
+
cache4.set(a4, newValue);
|
|
100
|
+
return newValue;
|
|
101
|
+
}
|
|
102
|
+
return cachedValue;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function memoize5(fn) {
|
|
106
|
+
const memoize5Cache = new WeakMap();
|
|
107
|
+
return function memoized(a1, a2, a3, a4, a5) {
|
|
108
|
+
let cache2 = memoize5Cache.get(a1);
|
|
109
|
+
if (!cache2) {
|
|
110
|
+
cache2 = new WeakMap();
|
|
111
|
+
memoize5Cache.set(a1, cache2);
|
|
112
|
+
const cache3 = new WeakMap();
|
|
113
|
+
cache2.set(a2, cache3);
|
|
114
|
+
const cache4 = new WeakMap();
|
|
115
|
+
cache3.set(a3, cache4);
|
|
116
|
+
const cache5 = new WeakMap();
|
|
117
|
+
cache4.set(a4, cache5);
|
|
118
|
+
const newValue = fn(a1, a2, a3, a4, a5);
|
|
119
|
+
cache5.set(a5, newValue);
|
|
120
|
+
return newValue;
|
|
121
|
+
}
|
|
122
|
+
let cache3 = cache2.get(a2);
|
|
123
|
+
if (!cache3) {
|
|
124
|
+
cache3 = new WeakMap();
|
|
125
|
+
cache2.set(a2, cache3);
|
|
126
|
+
const cache4 = new WeakMap();
|
|
127
|
+
cache3.set(a3, cache4);
|
|
128
|
+
const cache5 = new WeakMap();
|
|
129
|
+
cache4.set(a4, cache5);
|
|
130
|
+
const newValue = fn(a1, a2, a3, a4, a5);
|
|
131
|
+
cache5.set(a5, newValue);
|
|
132
|
+
return newValue;
|
|
133
|
+
}
|
|
134
|
+
let cache4 = cache3.get(a3);
|
|
135
|
+
if (!cache4) {
|
|
136
|
+
cache4 = new WeakMap();
|
|
137
|
+
cache3.set(a3, cache4);
|
|
138
|
+
const cache5 = new WeakMap();
|
|
139
|
+
cache4.set(a4, cache5);
|
|
140
|
+
const newValue = fn(a1, a2, a3, a4, a5);
|
|
141
|
+
cache5.set(a5, newValue);
|
|
142
|
+
return newValue;
|
|
143
|
+
}
|
|
144
|
+
let cache5 = cache4.get(a4);
|
|
145
|
+
if (!cache5) {
|
|
146
|
+
cache5 = new WeakMap();
|
|
147
|
+
cache4.set(a4, cache5);
|
|
148
|
+
const newValue = fn(a1, a2, a3, a4, a5);
|
|
149
|
+
cache5.set(a5, newValue);
|
|
150
|
+
return newValue;
|
|
151
|
+
}
|
|
152
|
+
const cachedValue = cache5.get(a5);
|
|
153
|
+
if (cachedValue === undefined) {
|
|
154
|
+
const newValue = fn(a1, a2, a3, a4, a5);
|
|
155
|
+
cache5.set(a5, newValue);
|
|
156
|
+
return newValue;
|
|
157
|
+
}
|
|
158
|
+
return cachedValue;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const memoize2of4cache = new WeakMap();
|
|
162
|
+
export function memoize2of4(fn) {
|
|
163
|
+
return function memoized(a1, a2, a3, a4) {
|
|
164
|
+
let cache2 = memoize2of4cache.get(a1);
|
|
165
|
+
if (!cache2) {
|
|
166
|
+
cache2 = new WeakMap();
|
|
167
|
+
memoize2of4cache.set(a1, cache2);
|
|
168
|
+
const newValue = fn(a1, a2, a3, a4);
|
|
169
|
+
cache2.set(a2, newValue);
|
|
170
|
+
return newValue;
|
|
171
|
+
}
|
|
172
|
+
const cachedValue = cache2.get(a2);
|
|
173
|
+
if (cachedValue === undefined) {
|
|
174
|
+
const newValue = fn(a1, a2, a3, a4);
|
|
175
|
+
cache2.set(a2, newValue);
|
|
176
|
+
return newValue;
|
|
177
|
+
}
|
|
178
|
+
return cachedValue;
|
|
179
|
+
};
|
|
180
|
+
}
|
package/esm/mergeDeep.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isSome } from './helpers.js';
|
|
2
|
+
export function mergeDeep(sources, respectPrototype = false) {
|
|
3
|
+
const target = sources[0] || {};
|
|
4
|
+
const output = {};
|
|
5
|
+
if (respectPrototype) {
|
|
6
|
+
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(target)));
|
|
7
|
+
}
|
|
8
|
+
for (const source of sources) {
|
|
9
|
+
if (isObject(target) && isObject(source)) {
|
|
10
|
+
if (respectPrototype) {
|
|
11
|
+
const outputPrototype = Object.getPrototypeOf(output);
|
|
12
|
+
const sourcePrototype = Object.getPrototypeOf(source);
|
|
13
|
+
if (sourcePrototype) {
|
|
14
|
+
for (const key of Object.getOwnPropertyNames(sourcePrototype)) {
|
|
15
|
+
const descriptor = Object.getOwnPropertyDescriptor(sourcePrototype, key);
|
|
16
|
+
if (isSome(descriptor)) {
|
|
17
|
+
Object.defineProperty(outputPrototype, key, descriptor);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const key in source) {
|
|
23
|
+
if (isObject(source[key])) {
|
|
24
|
+
if (!(key in output)) {
|
|
25
|
+
Object.assign(output, { [key]: source[key] });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
output[key] = mergeDeep([output[key], source[key]], respectPrototype);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
Object.assign(output, { [key]: source[key] });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return output;
|
|
38
|
+
}
|
|
39
|
+
function isObject(item) {
|
|
40
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
41
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export function observableToAsyncIterable(observable) {
|
|
2
|
+
const pullQueue = [];
|
|
3
|
+
const pushQueue = [];
|
|
4
|
+
let listening = true;
|
|
5
|
+
const pushValue = (value) => {
|
|
6
|
+
if (pullQueue.length !== 0) {
|
|
7
|
+
// It is safe to use the ! operator here as we check the length.
|
|
8
|
+
pullQueue.shift()({ value, done: false });
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
pushQueue.push({ value, done: false });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const pushError = (error) => {
|
|
15
|
+
if (pullQueue.length !== 0) {
|
|
16
|
+
// It is safe to use the ! operator here as we check the length.
|
|
17
|
+
pullQueue.shift()({ value: { errors: [error] }, done: false });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
pushQueue.push({ value: { errors: [error] }, done: false });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const pushDone = () => {
|
|
24
|
+
if (pullQueue.length !== 0) {
|
|
25
|
+
// It is safe to use the ! operator here as we check the length.
|
|
26
|
+
pullQueue.shift()({ done: true });
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
pushQueue.push({ done: true });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const pullValue = () => new Promise(resolve => {
|
|
33
|
+
if (pushQueue.length !== 0) {
|
|
34
|
+
const element = pushQueue.shift();
|
|
35
|
+
// either {value: {errors: [...]}} or {value: ...}
|
|
36
|
+
resolve(element);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
pullQueue.push(resolve);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const subscription = observable.subscribe({
|
|
43
|
+
next(value) {
|
|
44
|
+
pushValue(value);
|
|
45
|
+
},
|
|
46
|
+
error(err) {
|
|
47
|
+
pushError(err);
|
|
48
|
+
},
|
|
49
|
+
complete() {
|
|
50
|
+
pushDone();
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const emptyQueue = () => {
|
|
54
|
+
if (listening) {
|
|
55
|
+
listening = false;
|
|
56
|
+
subscription.unsubscribe();
|
|
57
|
+
for (const resolve of pullQueue) {
|
|
58
|
+
resolve({ value: undefined, done: true });
|
|
59
|
+
}
|
|
60
|
+
pullQueue.length = 0;
|
|
61
|
+
pushQueue.length = 0;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
next() {
|
|
66
|
+
// return is a defined method, so it is safe to call it.
|
|
67
|
+
return listening ? pullValue() : this.return();
|
|
68
|
+
},
|
|
69
|
+
return() {
|
|
70
|
+
emptyQueue();
|
|
71
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
72
|
+
},
|
|
73
|
+
throw(error) {
|
|
74
|
+
emptyQueue();
|
|
75
|
+
return Promise.reject(error);
|
|
76
|
+
},
|
|
77
|
+
[Symbol.asyncIterator]() {
|
|
78
|
+
return this;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { buildClientSchema } from 'graphql';
|
|
2
|
+
function stripBOM(content) {
|
|
3
|
+
content = content.toString();
|
|
4
|
+
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
5
|
+
// because the buffer-to-string conversion in `fs.readFileSync()`
|
|
6
|
+
// translates it to FEFF, the UTF-16 BOM.
|
|
7
|
+
if (content.charCodeAt(0) === 0xfeff) {
|
|
8
|
+
content = content.slice(1);
|
|
9
|
+
}
|
|
10
|
+
return content;
|
|
11
|
+
}
|
|
12
|
+
function parseBOM(content) {
|
|
13
|
+
return JSON.parse(stripBOM(content));
|
|
14
|
+
}
|
|
15
|
+
export function parseGraphQLJSON(location, jsonContent, options) {
|
|
16
|
+
let parsedJson = parseBOM(jsonContent);
|
|
17
|
+
if (parsedJson.data) {
|
|
18
|
+
parsedJson = parsedJson.data;
|
|
19
|
+
}
|
|
20
|
+
if (parsedJson.kind === 'Document') {
|
|
21
|
+
return {
|
|
22
|
+
location,
|
|
23
|
+
document: parsedJson,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else if (parsedJson.__schema) {
|
|
27
|
+
const schema = buildClientSchema(parsedJson, options);
|
|
28
|
+
return {
|
|
29
|
+
location,
|
|
30
|
+
schema,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (typeof parsedJson === 'string') {
|
|
34
|
+
return {
|
|
35
|
+
location,
|
|
36
|
+
rawSDL: parsedJson,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Not valid JSON content`);
|
|
40
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Kind, parse, Source as GraphQLSource, visit, isTypeSystemDefinitionNode, print, } from 'graphql';
|
|
2
|
+
import { dedentBlockStringValue, getLeadingCommentBlock } from './comments.js';
|
|
3
|
+
export function parseGraphQLSDL(location, rawSDL, options = {}) {
|
|
4
|
+
let document;
|
|
5
|
+
try {
|
|
6
|
+
if (options.commentDescriptions && rawSDL.includes('#')) {
|
|
7
|
+
document = transformCommentsToDescriptions(rawSDL, options);
|
|
8
|
+
// If noLocation=true, we need to make sure to print and parse it again, to remove locations,
|
|
9
|
+
// since `transformCommentsToDescriptions` must have locations set in order to transform the comments
|
|
10
|
+
// into descriptions.
|
|
11
|
+
if (options.noLocation) {
|
|
12
|
+
document = parse(print(document), options);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
document = parse(new GraphQLSource(rawSDL, location), options);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
if (e.message.includes('EOF') && rawSDL.replace(/(\#[^*]*)/g, '').trim() === '') {
|
|
21
|
+
document = {
|
|
22
|
+
kind: Kind.DOCUMENT,
|
|
23
|
+
definitions: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
location,
|
|
32
|
+
document,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function transformCommentsToDescriptions(sourceSdl, options = {}) {
|
|
36
|
+
const parsedDoc = parse(sourceSdl, {
|
|
37
|
+
...options,
|
|
38
|
+
noLocation: false,
|
|
39
|
+
});
|
|
40
|
+
const modifiedDoc = visit(parsedDoc, {
|
|
41
|
+
leave: (node) => {
|
|
42
|
+
if (isDescribable(node)) {
|
|
43
|
+
const rawValue = getLeadingCommentBlock(node);
|
|
44
|
+
if (rawValue !== undefined) {
|
|
45
|
+
const commentsBlock = dedentBlockStringValue('\n' + rawValue);
|
|
46
|
+
const isBlock = commentsBlock.includes('\n');
|
|
47
|
+
if (!node.description) {
|
|
48
|
+
return {
|
|
49
|
+
...node,
|
|
50
|
+
description: {
|
|
51
|
+
kind: Kind.STRING,
|
|
52
|
+
value: commentsBlock,
|
|
53
|
+
block: isBlock,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return {
|
|
59
|
+
...node,
|
|
60
|
+
description: {
|
|
61
|
+
...node.description,
|
|
62
|
+
value: node.description.value + '\n' + commentsBlock,
|
|
63
|
+
block: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return modifiedDoc;
|
|
72
|
+
}
|
|
73
|
+
export function isDescribable(node) {
|
|
74
|
+
return (isTypeSystemDefinitionNode(node) ||
|
|
75
|
+
node.kind === Kind.FIELD_DEFINITION ||
|
|
76
|
+
node.kind === Kind.INPUT_VALUE_DEFINITION ||
|
|
77
|
+
node.kind === Kind.ENUM_VALUE_DEFINITION);
|
|
78
|
+
}
|