@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/cjs/mergeDeep.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeDeep = void 0;
|
|
4
|
+
const helpers_js_1 = require("./helpers.js");
|
|
5
|
+
function mergeDeep(sources, respectPrototype = false) {
|
|
6
|
+
const target = sources[0] || {};
|
|
7
|
+
const output = {};
|
|
8
|
+
if (respectPrototype) {
|
|
9
|
+
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(target)));
|
|
10
|
+
}
|
|
11
|
+
for (const source of sources) {
|
|
12
|
+
if (isObject(target) && isObject(source)) {
|
|
13
|
+
if (respectPrototype) {
|
|
14
|
+
const outputPrototype = Object.getPrototypeOf(output);
|
|
15
|
+
const sourcePrototype = Object.getPrototypeOf(source);
|
|
16
|
+
if (sourcePrototype) {
|
|
17
|
+
for (const key of Object.getOwnPropertyNames(sourcePrototype)) {
|
|
18
|
+
const descriptor = Object.getOwnPropertyDescriptor(sourcePrototype, key);
|
|
19
|
+
if ((0, helpers_js_1.isSome)(descriptor)) {
|
|
20
|
+
Object.defineProperty(outputPrototype, key, descriptor);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const key in source) {
|
|
26
|
+
if (isObject(source[key])) {
|
|
27
|
+
if (!(key in output)) {
|
|
28
|
+
Object.assign(output, { [key]: source[key] });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
output[key] = mergeDeep([output[key], source[key]], respectPrototype);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
Object.assign(output, { [key]: source[key] });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return output;
|
|
41
|
+
}
|
|
42
|
+
exports.mergeDeep = mergeDeep;
|
|
43
|
+
function isObject(item) {
|
|
44
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
45
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observableToAsyncIterable = void 0;
|
|
4
|
+
function observableToAsyncIterable(observable) {
|
|
5
|
+
const pullQueue = [];
|
|
6
|
+
const pushQueue = [];
|
|
7
|
+
let listening = true;
|
|
8
|
+
const pushValue = (value) => {
|
|
9
|
+
if (pullQueue.length !== 0) {
|
|
10
|
+
// It is safe to use the ! operator here as we check the length.
|
|
11
|
+
pullQueue.shift()({ value, done: false });
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
pushQueue.push({ value, done: false });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const pushError = (error) => {
|
|
18
|
+
if (pullQueue.length !== 0) {
|
|
19
|
+
// It is safe to use the ! operator here as we check the length.
|
|
20
|
+
pullQueue.shift()({ value: { errors: [error] }, done: false });
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
pushQueue.push({ value: { errors: [error] }, done: false });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const pushDone = () => {
|
|
27
|
+
if (pullQueue.length !== 0) {
|
|
28
|
+
// It is safe to use the ! operator here as we check the length.
|
|
29
|
+
pullQueue.shift()({ done: true });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
pushQueue.push({ done: true });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const pullValue = () => new Promise(resolve => {
|
|
36
|
+
if (pushQueue.length !== 0) {
|
|
37
|
+
const element = pushQueue.shift();
|
|
38
|
+
// either {value: {errors: [...]}} or {value: ...}
|
|
39
|
+
resolve(element);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
pullQueue.push(resolve);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const subscription = observable.subscribe({
|
|
46
|
+
next(value) {
|
|
47
|
+
pushValue(value);
|
|
48
|
+
},
|
|
49
|
+
error(err) {
|
|
50
|
+
pushError(err);
|
|
51
|
+
},
|
|
52
|
+
complete() {
|
|
53
|
+
pushDone();
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const emptyQueue = () => {
|
|
57
|
+
if (listening) {
|
|
58
|
+
listening = false;
|
|
59
|
+
subscription.unsubscribe();
|
|
60
|
+
for (const resolve of pullQueue) {
|
|
61
|
+
resolve({ value: undefined, done: true });
|
|
62
|
+
}
|
|
63
|
+
pullQueue.length = 0;
|
|
64
|
+
pushQueue.length = 0;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
next() {
|
|
69
|
+
// return is a defined method, so it is safe to call it.
|
|
70
|
+
return listening ? pullValue() : this.return();
|
|
71
|
+
},
|
|
72
|
+
return() {
|
|
73
|
+
emptyQueue();
|
|
74
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
75
|
+
},
|
|
76
|
+
throw(error) {
|
|
77
|
+
emptyQueue();
|
|
78
|
+
return Promise.reject(error);
|
|
79
|
+
},
|
|
80
|
+
[Symbol.asyncIterator]() {
|
|
81
|
+
return this;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
exports.observableToAsyncIterable = observableToAsyncIterable;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGraphQLJSON = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function stripBOM(content) {
|
|
6
|
+
content = content.toString();
|
|
7
|
+
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
8
|
+
// because the buffer-to-string conversion in `fs.readFileSync()`
|
|
9
|
+
// translates it to FEFF, the UTF-16 BOM.
|
|
10
|
+
if (content.charCodeAt(0) === 0xfeff) {
|
|
11
|
+
content = content.slice(1);
|
|
12
|
+
}
|
|
13
|
+
return content;
|
|
14
|
+
}
|
|
15
|
+
function parseBOM(content) {
|
|
16
|
+
return JSON.parse(stripBOM(content));
|
|
17
|
+
}
|
|
18
|
+
function parseGraphQLJSON(location, jsonContent, options) {
|
|
19
|
+
let parsedJson = parseBOM(jsonContent);
|
|
20
|
+
if (parsedJson.data) {
|
|
21
|
+
parsedJson = parsedJson.data;
|
|
22
|
+
}
|
|
23
|
+
if (parsedJson.kind === 'Document') {
|
|
24
|
+
return {
|
|
25
|
+
location,
|
|
26
|
+
document: parsedJson,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else if (parsedJson.__schema) {
|
|
30
|
+
const schema = (0, graphql_1.buildClientSchema)(parsedJson, options);
|
|
31
|
+
return {
|
|
32
|
+
location,
|
|
33
|
+
schema,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else if (typeof parsedJson === 'string') {
|
|
37
|
+
return {
|
|
38
|
+
location,
|
|
39
|
+
rawSDL: parsedJson,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Not valid JSON content`);
|
|
43
|
+
}
|
|
44
|
+
exports.parseGraphQLJSON = parseGraphQLJSON;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDescribable = exports.transformCommentsToDescriptions = exports.parseGraphQLSDL = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const comments_js_1 = require("./comments.js");
|
|
6
|
+
function parseGraphQLSDL(location, rawSDL, options = {}) {
|
|
7
|
+
let document;
|
|
8
|
+
try {
|
|
9
|
+
if (options.commentDescriptions && rawSDL.includes('#')) {
|
|
10
|
+
document = transformCommentsToDescriptions(rawSDL, options);
|
|
11
|
+
// If noLocation=true, we need to make sure to print and parse it again, to remove locations,
|
|
12
|
+
// since `transformCommentsToDescriptions` must have locations set in order to transform the comments
|
|
13
|
+
// into descriptions.
|
|
14
|
+
if (options.noLocation) {
|
|
15
|
+
document = (0, graphql_1.parse)((0, graphql_1.print)(document), options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
document = (0, graphql_1.parse)(new graphql_1.Source(rawSDL, location), options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
if (e.message.includes('EOF') && rawSDL.replace(/(\#[^*]*)/g, '').trim() === '') {
|
|
24
|
+
document = {
|
|
25
|
+
kind: graphql_1.Kind.DOCUMENT,
|
|
26
|
+
definitions: [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
location,
|
|
35
|
+
document,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.parseGraphQLSDL = parseGraphQLSDL;
|
|
39
|
+
function transformCommentsToDescriptions(sourceSdl, options = {}) {
|
|
40
|
+
const parsedDoc = (0, graphql_1.parse)(sourceSdl, {
|
|
41
|
+
...options,
|
|
42
|
+
noLocation: false,
|
|
43
|
+
});
|
|
44
|
+
const modifiedDoc = (0, graphql_1.visit)(parsedDoc, {
|
|
45
|
+
leave: (node) => {
|
|
46
|
+
if (isDescribable(node)) {
|
|
47
|
+
const rawValue = (0, comments_js_1.getLeadingCommentBlock)(node);
|
|
48
|
+
if (rawValue !== undefined) {
|
|
49
|
+
const commentsBlock = (0, comments_js_1.dedentBlockStringValue)('\n' + rawValue);
|
|
50
|
+
const isBlock = commentsBlock.includes('\n');
|
|
51
|
+
if (!node.description) {
|
|
52
|
+
return {
|
|
53
|
+
...node,
|
|
54
|
+
description: {
|
|
55
|
+
kind: graphql_1.Kind.STRING,
|
|
56
|
+
value: commentsBlock,
|
|
57
|
+
block: isBlock,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return {
|
|
63
|
+
...node,
|
|
64
|
+
description: {
|
|
65
|
+
...node.description,
|
|
66
|
+
value: node.description.value + '\n' + commentsBlock,
|
|
67
|
+
block: true,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return modifiedDoc;
|
|
76
|
+
}
|
|
77
|
+
exports.transformCommentsToDescriptions = transformCommentsToDescriptions;
|
|
78
|
+
function isDescribable(node) {
|
|
79
|
+
return ((0, graphql_1.isTypeSystemDefinitionNode)(node) ||
|
|
80
|
+
node.kind === graphql_1.Kind.FIELD_DEFINITION ||
|
|
81
|
+
node.kind === graphql_1.Kind.INPUT_VALUE_DEFINITION ||
|
|
82
|
+
node.kind === graphql_1.Kind.ENUM_VALUE_DEFINITION);
|
|
83
|
+
}
|
|
84
|
+
exports.isDescribable = isDescribable;
|