@graphql-tools/executor 0.0.1-alpha-20221025014654-e3be5659
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/README.md +3 -0
- package/cjs/execution/AccumulatorMap.js +21 -0
- package/cjs/execution/collectFields.js +114 -0
- package/cjs/execution/execute.js +792 -0
- package/cjs/execution/index.js +10 -0
- package/cjs/execution/mapAsyncIterator.js +53 -0
- package/cjs/execution/subscribe.js +164 -0
- package/cjs/execution/values.js +168 -0
- package/cjs/index.js +4 -0
- package/cjs/package.json +1 -0
- package/esm/execution/AccumulatorMap.js +17 -0
- package/esm/execution/collectFields.js +109 -0
- package/esm/execution/execute.js +779 -0
- package/esm/execution/index.js +5 -0
- package/esm/execution/mapAsyncIterator.js +49 -0
- package/esm/execution/subscribe.js +159 -0
- package/esm/execution/values.js +162 -0
- package/esm/index.js +1 -0
- package/package.json +58 -0
- package/typings/execution/AccumulatorMap.d.cts +7 -0
- package/typings/execution/AccumulatorMap.d.ts +7 -0
- package/typings/execution/collectFields.d.cts +27 -0
- package/typings/execution/collectFields.d.ts +27 -0
- package/typings/execution/execute.d.cts +196 -0
- package/typings/execution/execute.d.ts +196 -0
- package/typings/execution/index.d.cts +5 -0
- package/typings/execution/index.d.ts +5 -0
- package/typings/execution/mapAsyncIterator.d.cts +6 -0
- package/typings/execution/mapAsyncIterator.d.ts +6 -0
- package/typings/execution/subscribe.d.cts +56 -0
- package/typings/execution/subscribe.d.ts +56 -0
- package/typings/execution/values.d.cts +54 -0
- package/typings/execution/values.d.ts +54 -0
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccumulatorMap = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* ES6 Map with additional `add` method to accumulate items.
|
|
6
|
+
*/
|
|
7
|
+
class AccumulatorMap extends Map {
|
|
8
|
+
get [Symbol.toStringTag]() {
|
|
9
|
+
return 'AccumulatorMap';
|
|
10
|
+
}
|
|
11
|
+
add(key, item) {
|
|
12
|
+
const group = this.get(key);
|
|
13
|
+
if (group === undefined) {
|
|
14
|
+
this.set(key, [item]);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
group.push(item);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.AccumulatorMap = AccumulatorMap;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectSubfields = exports.collectFields = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const AccumulatorMap_js_1 = require("./AccumulatorMap.js");
|
|
6
|
+
const values_js_1 = require("./values.js");
|
|
7
|
+
/**
|
|
8
|
+
* Given a selectionSet, collects all of the fields and returns them.
|
|
9
|
+
*
|
|
10
|
+
* CollectFields requires the "runtime type" of an object. For a field that
|
|
11
|
+
* returns an Interface or Union type, the "runtime type" will be the actual
|
|
12
|
+
* object type returned by that field.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
function collectFields(schema, fragments, variableValues, runtimeType, selectionSet) {
|
|
17
|
+
const fields = new AccumulatorMap_js_1.AccumulatorMap();
|
|
18
|
+
collectFieldsImpl(schema, fragments, variableValues, runtimeType, selectionSet, fields, new Set());
|
|
19
|
+
return fields;
|
|
20
|
+
}
|
|
21
|
+
exports.collectFields = collectFields;
|
|
22
|
+
/**
|
|
23
|
+
* Given an array of field nodes, collects all of the subfields of the passed
|
|
24
|
+
* in fields, and returns them at the end.
|
|
25
|
+
*
|
|
26
|
+
* CollectSubFields requires the "return type" of an object. For a field that
|
|
27
|
+
* returns an Interface or Union type, the "return type" will be the actual
|
|
28
|
+
* object type returned by that field.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function collectSubfields(schema, fragments, variableValues, returnType, fieldNodes) {
|
|
33
|
+
const subFieldNodes = new AccumulatorMap_js_1.AccumulatorMap();
|
|
34
|
+
const visitedFragmentNames = new Set();
|
|
35
|
+
for (const node of fieldNodes) {
|
|
36
|
+
if (node.selectionSet) {
|
|
37
|
+
collectFieldsImpl(schema, fragments, variableValues, returnType, node.selectionSet, subFieldNodes, visitedFragmentNames);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return subFieldNodes;
|
|
41
|
+
}
|
|
42
|
+
exports.collectSubfields = collectSubfields;
|
|
43
|
+
function collectFieldsImpl(schema, fragments, variableValues, runtimeType, selectionSet, fields, visitedFragmentNames) {
|
|
44
|
+
for (const selection of selectionSet.selections) {
|
|
45
|
+
switch (selection.kind) {
|
|
46
|
+
case graphql_1.Kind.FIELD: {
|
|
47
|
+
if (!shouldIncludeNode(variableValues, selection)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
fields.add(getFieldEntryKey(selection), selection);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case graphql_1.Kind.INLINE_FRAGMENT: {
|
|
54
|
+
if (!shouldIncludeNode(variableValues, selection) ||
|
|
55
|
+
!doesFragmentConditionMatch(schema, selection, runtimeType)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
collectFieldsImpl(schema, fragments, variableValues, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case graphql_1.Kind.FRAGMENT_SPREAD: {
|
|
62
|
+
const fragName = selection.name.value;
|
|
63
|
+
if (visitedFragmentNames.has(fragName) || !shouldIncludeNode(variableValues, selection)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
visitedFragmentNames.add(fragName);
|
|
67
|
+
const fragment = fragments[fragName];
|
|
68
|
+
if (!fragment || !doesFragmentConditionMatch(schema, fragment, runtimeType)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
collectFieldsImpl(schema, fragments, variableValues, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Determines if a field should be included based on the `@include` and `@skip`
|
|
79
|
+
* directives, where `@skip` has higher precedence than `@include`.
|
|
80
|
+
*/
|
|
81
|
+
function shouldIncludeNode(variableValues, node) {
|
|
82
|
+
const skip = (0, values_js_1.getDirectiveValues)(graphql_1.GraphQLSkipDirective, node, variableValues);
|
|
83
|
+
if ((skip === null || skip === void 0 ? void 0 : skip['if']) === true) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const include = (0, values_js_1.getDirectiveValues)(graphql_1.GraphQLIncludeDirective, node, variableValues);
|
|
87
|
+
if ((include === null || include === void 0 ? void 0 : include['if']) === false) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Determines if a fragment is applicable to the given type.
|
|
94
|
+
*/
|
|
95
|
+
function doesFragmentConditionMatch(schema, fragment, type) {
|
|
96
|
+
const typeConditionNode = fragment.typeCondition;
|
|
97
|
+
if (!typeConditionNode) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
const conditionalType = (0, graphql_1.typeFromAST)(schema, typeConditionNode);
|
|
101
|
+
if (conditionalType === type) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if ((0, graphql_1.isAbstractType)(conditionalType)) {
|
|
105
|
+
return schema.isSubType(conditionalType, type);
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Implements the logic to compute the key of a given field's entry
|
|
111
|
+
*/
|
|
112
|
+
function getFieldEntryKey(node) {
|
|
113
|
+
return node.alias ? node.alias.value : node.name.value;
|
|
114
|
+
}
|