@graphitation/supermassive 2.6.1 → 3.0.0-alpha.3
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/.eslintcache +1 -1
- package/CHANGELOG.md +17 -1
- package/lib/__testUtils__/execute.d.ts +13 -0
- package/lib/__testUtils__/execute.d.ts.map +1 -0
- package/lib/__testUtils__/execute.js +196 -0
- package/lib/__testUtils__/execute.js.map +7 -0
- package/lib/__testUtils__/execute.mjs +174 -0
- package/lib/__testUtils__/execute.mjs.map +7 -0
- package/lib/benchmarks/index.js +11 -20
- package/lib/benchmarks/index.js.map +3 -3
- package/lib/benchmarks/index.mjs +12 -23
- package/lib/benchmarks/index.mjs.map +2 -2
- package/lib/benchmarks/swapi-schema/index.d.ts +4 -2
- package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/index.js +8 -2
- package/lib/benchmarks/swapi-schema/index.js.map +2 -2
- package/lib/benchmarks/swapi-schema/index.mjs +8 -2
- package/lib/benchmarks/swapi-schema/index.mjs.map +2 -2
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts +7 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts.map +1 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.js +916 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.js.map +7 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.mjs +903 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.mjs.map +7 -0
- package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +53 -17
- package/lib/benchmarks/swapi-schema/resolvers.js.map +2 -2
- package/lib/benchmarks/swapi-schema/resolvers.mjs +54 -18
- package/lib/benchmarks/swapi-schema/resolvers.mjs.map +2 -2
- package/lib/collectFields.d.ts +27 -10
- package/lib/collectFields.d.ts.map +1 -1
- package/lib/collectFields.js +146 -80
- package/lib/collectFields.js.map +3 -3
- package/lib/collectFields.mjs +143 -81
- package/lib/collectFields.mjs.map +2 -2
- package/lib/executeWithSchema.d.ts +1 -1
- package/lib/executeWithSchema.d.ts.map +1 -1
- package/lib/executeWithSchema.js +7 -13
- package/lib/executeWithSchema.js.map +2 -2
- package/lib/executeWithSchema.mjs +9 -20
- package/lib/executeWithSchema.mjs.map +2 -2
- package/lib/executeWithoutSchema.d.ts +53 -16
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +1076 -274
- package/lib/executeWithoutSchema.js.map +3 -3
- package/lib/executeWithoutSchema.mjs +1092 -281
- package/lib/executeWithoutSchema.mjs.map +3 -3
- package/lib/index.d.ts +3 -9
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -7
- package/lib/index.js.map +2 -2
- package/lib/index.mjs +3 -10
- package/lib/index.mjs.map +2 -2
- package/lib/jsutils/AccumulatorMap.d.ts +8 -0
- package/lib/jsutils/AccumulatorMap.d.ts.map +1 -0
- package/lib/jsutils/AccumulatorMap.js +36 -0
- package/lib/jsutils/AccumulatorMap.js.map +7 -0
- package/lib/jsutils/AccumulatorMap.mjs +17 -0
- package/lib/jsutils/AccumulatorMap.mjs.map +7 -0
- package/lib/jsutils/didYouMean.d.ts +1 -2
- package/lib/jsutils/didYouMean.d.ts.map +1 -1
- package/lib/jsutils/didYouMean.js.map +2 -2
- package/lib/jsutils/didYouMean.mjs.map +2 -2
- package/lib/jsutils/instanceOf.js.map +2 -2
- package/lib/jsutils/instanceOf.mjs.map +2 -2
- package/lib/schema/definition.d.ts +95 -0
- package/lib/schema/definition.d.ts.map +1 -0
- package/lib/schema/definition.js +77 -0
- package/lib/schema/definition.js.map +7 -0
- package/lib/schema/definition.mjs +58 -0
- package/lib/schema/definition.mjs.map +7 -0
- package/lib/schema/directives.d.ts +41 -0
- package/lib/schema/directives.d.ts.map +1 -0
- package/lib/schema/directives.js +82 -0
- package/lib/schema/directives.js.map +7 -0
- package/lib/schema/directives.mjs +65 -0
- package/lib/schema/directives.mjs.map +7 -0
- package/lib/schema/fragment.d.ts +41 -0
- package/lib/schema/fragment.d.ts.map +1 -0
- package/lib/schema/fragment.js +270 -0
- package/lib/schema/fragment.js.map +7 -0
- package/lib/schema/fragment.mjs +267 -0
- package/lib/schema/fragment.mjs.map +7 -0
- package/lib/schema/reference.d.ts +12 -0
- package/lib/schema/reference.d.ts.map +1 -0
- package/lib/schema/reference.js +137 -0
- package/lib/schema/reference.js.map +7 -0
- package/lib/schema/reference.mjs +118 -0
- package/lib/schema/reference.mjs.map +7 -0
- package/lib/schema/resolvers.d.ts +9 -0
- package/lib/schema/resolvers.d.ts.map +1 -0
- package/lib/schema/resolvers.js +47 -0
- package/lib/schema/resolvers.js.map +7 -0
- package/lib/schema/resolvers.mjs +35 -0
- package/lib/schema/resolvers.mjs.map +7 -0
- package/lib/subscribeWithSchema.d.ts +3 -2
- package/lib/subscribeWithSchema.d.ts.map +1 -1
- package/lib/subscribeWithSchema.js +7 -13
- package/lib/subscribeWithSchema.js.map +2 -2
- package/lib/subscribeWithSchema.mjs +9 -20
- package/lib/subscribeWithSchema.mjs.map +2 -2
- package/lib/subscribeWithoutSchema.d.ts +3 -35
- package/lib/subscribeWithoutSchema.d.ts.map +1 -1
- package/lib/subscribeWithoutSchema.js +1 -163
- package/lib/subscribeWithoutSchema.js.map +2 -2
- package/lib/subscribeWithoutSchema.mjs +2 -175
- package/lib/subscribeWithoutSchema.mjs.map +2 -2
- package/lib/types.d.ts +71 -29
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +14 -0
- package/lib/types.js.map +2 -2
- package/lib/types.mjs +11 -0
- package/lib/types.mjs.map +3 -3
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.d.ts +9 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.d.ts.map +1 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.js +303 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.js.map +7 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.mjs +317 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.mjs.map +7 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.d.ts +3 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.d.ts.map +1 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.js +34 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.js.map +7 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.mjs +17 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.mjs.map +7 -0
- package/lib/utilities/coerceInputValue.d.ts +10 -0
- package/lib/utilities/coerceInputValue.d.ts.map +1 -0
- package/lib/utilities/coerceInputValue.js +181 -0
- package/lib/utilities/coerceInputValue.js.map +7 -0
- package/lib/utilities/coerceInputValue.mjs +167 -0
- package/lib/utilities/coerceInputValue.mjs.map +7 -0
- package/lib/utilities/decodeASTSchema.d.ts +7 -0
- package/lib/utilities/decodeASTSchema.d.ts.map +1 -0
- package/lib/utilities/decodeASTSchema.js +243 -0
- package/lib/utilities/decodeASTSchema.js.map +7 -0
- package/lib/utilities/decodeASTSchema.mjs +242 -0
- package/lib/utilities/decodeASTSchema.mjs.map +7 -0
- package/lib/utilities/encodeASTSchema.d.ts +4 -0
- package/lib/utilities/encodeASTSchema.d.ts.map +1 -0
- package/lib/utilities/encodeASTSchema.js +122 -0
- package/lib/utilities/encodeASTSchema.js.map +7 -0
- package/lib/utilities/encodeASTSchema.mjs +105 -0
- package/lib/utilities/encodeASTSchema.mjs.map +7 -0
- package/lib/utilities/getSchemaFragment.d.ts +4 -0
- package/lib/utilities/getSchemaFragment.d.ts.map +1 -0
- package/lib/utilities/getSchemaFragment.js +38 -0
- package/lib/utilities/getSchemaFragment.js.map +7 -0
- package/lib/utilities/getSchemaFragment.mjs +22 -0
- package/lib/utilities/getSchemaFragment.mjs.map +7 -0
- package/lib/utilities/makeReadableErrorPath.d.ts +3 -0
- package/lib/utilities/makeReadableErrorPath.d.ts.map +1 -0
- package/lib/utilities/makeReadableErrorPath.js +47 -0
- package/lib/utilities/makeReadableErrorPath.js.map +7 -0
- package/lib/utilities/makeReadableErrorPath.mjs +28 -0
- package/lib/utilities/makeReadableErrorPath.mjs.map +7 -0
- package/lib/utilities/mergeDefinitions.d.ts +8 -0
- package/lib/utilities/mergeDefinitions.d.ts.map +1 -0
- package/lib/utilities/mergeDefinitions.js +126 -0
- package/lib/utilities/mergeDefinitions.js.map +7 -0
- package/lib/utilities/mergeDefinitions.mjs +114 -0
- package/lib/utilities/mergeDefinitions.mjs.map +7 -0
- package/lib/utilities/mergeResolvers.d.ts +1 -1
- package/lib/utilities/mergeResolvers.d.ts.map +1 -1
- package/lib/utilities/mergeResolvers.js.map +2 -2
- package/lib/utilities/mergeResolvers.mjs.map +2 -2
- package/lib/utilities/typeNameFromAST.d.ts +1 -1
- package/lib/utilities/typeNameFromAST.d.ts.map +1 -1
- package/lib/utilities/typeNameFromAST.js.map +2 -2
- package/lib/utilities/typeNameFromAST.mjs.map +2 -2
- package/lib/utilities/valueFromAST.d.ts +27 -0
- package/lib/utilities/valueFromAST.d.ts.map +1 -0
- package/lib/utilities/valueFromAST.js +139 -0
- package/lib/utilities/valueFromAST.js.map +7 -0
- package/lib/utilities/valueFromAST.mjs +125 -0
- package/lib/utilities/valueFromAST.mjs.map +7 -0
- package/lib/utilities/valueFromASTUntyped.d.ts +21 -0
- package/lib/utilities/valueFromASTUntyped.d.ts.map +1 -0
- package/lib/utilities/valueFromASTUntyped.js +51 -0
- package/lib/utilities/valueFromASTUntyped.js.map +7 -0
- package/lib/utilities/valueFromASTUntyped.mjs +32 -0
- package/lib/utilities/valueFromASTUntyped.mjs.map +7 -0
- package/lib/values.d.ts +8 -13
- package/lib/values.d.ts.map +1 -1
- package/lib/values.js +83 -75
- package/lib/values.js.map +2 -2
- package/lib/values.mjs +85 -83
- package/lib/values.mjs.map +2 -2
- package/package.json +8 -9
- package/lib/definition.d.ts +0 -7
- package/lib/definition.d.ts.map +0 -1
- package/lib/definition.js +0 -59
- package/lib/definition.js.map +0 -7
- package/lib/definition.mjs +0 -40
- package/lib/definition.mjs.map +0 -7
- package/lib/directives.d.ts +0 -79
- package/lib/directives.d.ts.map +0 -1
- package/lib/directives.js +0 -160
- package/lib/directives.js.map +0 -7
- package/lib/directives.mjs +0 -146
- package/lib/directives.mjs.map +0 -7
- package/lib/extractImplicitTypesRuntime.d.ts +0 -4
- package/lib/extractImplicitTypesRuntime.d.ts.map +0 -1
- package/lib/extractImplicitTypesRuntime.js +0 -123
- package/lib/extractImplicitTypesRuntime.js.map +0 -7
- package/lib/extractImplicitTypesRuntime.mjs +0 -114
- package/lib/extractImplicitTypesRuntime.mjs.map +0 -7
package/lib/collectFields.d.ts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import { FieldNode
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { FieldNode } from "graphql";
|
|
2
|
+
import { ExecutionContext } from "./executeWithoutSchema";
|
|
3
|
+
export type FieldGroup = ReadonlyArray<FieldNode>;
|
|
4
|
+
export type GroupedFieldSet = Map<string, FieldGroup>;
|
|
5
|
+
export interface PatchFields {
|
|
6
|
+
label: string | undefined;
|
|
7
|
+
groupedFieldSet: GroupedFieldSet;
|
|
8
|
+
}
|
|
9
|
+
export interface FieldsAndPatches {
|
|
10
|
+
groupedFieldSet: GroupedFieldSet;
|
|
11
|
+
patches: Array<PatchFields>;
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
|
-
* Given a selectionSet,
|
|
6
|
-
* the passed in map of fields, and returns it at the end.
|
|
14
|
+
* Given a selectionSet, collects all of the fields and returns them.
|
|
7
15
|
*
|
|
8
|
-
* CollectFields requires the "runtime type" of an object. For a field
|
|
16
|
+
* CollectFields requires the "runtime type" of an object. For a field that
|
|
9
17
|
* returns an Interface or Union type, the "runtime type" will be the actual
|
|
10
|
-
*
|
|
18
|
+
* object type returned by that field.
|
|
11
19
|
*
|
|
12
20
|
* @internal
|
|
13
21
|
*/
|
|
14
|
-
export declare function collectFields(
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
export declare function collectFields(exeContext: ExecutionContext, runtimeTypeName: string): FieldsAndPatches;
|
|
23
|
+
/**
|
|
24
|
+
* Given an array of field nodes, collects all of the subfields of the passed
|
|
25
|
+
* in fields, and returns them at the end.
|
|
26
|
+
*
|
|
27
|
+
* CollectSubFields requires the "return type" of an object. For a field that
|
|
28
|
+
* returns an Interface or Union type, the "return type" will be the actual
|
|
29
|
+
* object type returned by that field.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare function collectSubfields(exeContext: ExecutionContext, returnTypeName: string, fieldGroup: FieldGroup): FieldsAndPatches;
|
|
17
34
|
//# sourceMappingURL=collectFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectFields.d.ts","sourceRoot":"","sources":["../src/collectFields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collectFields.d.ts","sourceRoot":"","sources":["../src/collectFields.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAMV,MAAM,SAAS,CAAC;AAUjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,gBAAgB,EAC5B,eAAe,EAAE,MAAM,GACtB,gBAAgB,CAalB;AAED;;;;;;;;;GASG;AAEH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,gBAAgB,EAC5B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,UAAU,GACrB,gBAAgB,CAuBlB"}
|
package/lib/collectFields.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,137 +17,201 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var collectFields_exports = {};
|
|
20
30
|
__export(collectFields_exports, {
|
|
21
|
-
collectFields: () => collectFields
|
|
31
|
+
collectFields: () => collectFields,
|
|
32
|
+
collectSubfields: () => collectSubfields
|
|
22
33
|
});
|
|
23
34
|
module.exports = __toCommonJS(collectFields_exports);
|
|
24
35
|
var import_graphql = require("graphql");
|
|
25
36
|
var import_values = require("./values");
|
|
26
|
-
var import_directives = require("./directives");
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
function collectFields(
|
|
37
|
+
var import_directives = require("./schema/directives");
|
|
38
|
+
var import_AccumulatorMap = require("./jsutils/AccumulatorMap");
|
|
39
|
+
var import_invariant = __toESM(require("invariant"));
|
|
40
|
+
function collectFields(exeContext, runtimeTypeName) {
|
|
41
|
+
const { operation } = exeContext;
|
|
42
|
+
const groupedFieldSet = new import_AccumulatorMap.AccumulatorMap();
|
|
43
|
+
const patches = [];
|
|
44
|
+
collectFieldsImpl(
|
|
45
|
+
exeContext,
|
|
46
|
+
runtimeTypeName,
|
|
47
|
+
operation.selectionSet,
|
|
48
|
+
groupedFieldSet,
|
|
49
|
+
patches,
|
|
50
|
+
/* @__PURE__ */ new Set()
|
|
51
|
+
);
|
|
52
|
+
return { groupedFieldSet, patches };
|
|
53
|
+
}
|
|
54
|
+
function collectSubfields(exeContext, returnTypeName, fieldGroup) {
|
|
55
|
+
const subGroupedFieldSet = new import_AccumulatorMap.AccumulatorMap();
|
|
56
|
+
const visitedFragmentNames = /* @__PURE__ */ new Set();
|
|
57
|
+
const subPatches = [];
|
|
58
|
+
const subFieldsAndPatches = {
|
|
59
|
+
groupedFieldSet: subGroupedFieldSet,
|
|
60
|
+
patches: subPatches
|
|
61
|
+
};
|
|
62
|
+
for (const node of fieldGroup) {
|
|
63
|
+
if (node.selectionSet) {
|
|
64
|
+
collectFieldsImpl(
|
|
65
|
+
exeContext,
|
|
66
|
+
returnTypeName,
|
|
67
|
+
node.selectionSet,
|
|
68
|
+
subGroupedFieldSet,
|
|
69
|
+
subPatches,
|
|
70
|
+
visitedFragmentNames
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return subFieldsAndPatches;
|
|
75
|
+
}
|
|
76
|
+
function collectFieldsImpl(exeContext, runtimeTypeName, selectionSet, groupedFieldSet, patches, visitedFragmentNames) {
|
|
30
77
|
for (const selection of selectionSet.selections) {
|
|
31
78
|
switch (selection.kind) {
|
|
32
79
|
case import_graphql.Kind.FIELD: {
|
|
33
|
-
if (!shouldIncludeNode(
|
|
80
|
+
if (!shouldIncludeNode(exeContext, selection)) {
|
|
34
81
|
continue;
|
|
35
82
|
}
|
|
36
|
-
|
|
37
|
-
const fieldList = fields.get(name);
|
|
38
|
-
if (fieldList !== void 0) {
|
|
39
|
-
fieldList.push(selection);
|
|
40
|
-
} else {
|
|
41
|
-
fields.set(name, [selection]);
|
|
42
|
-
}
|
|
83
|
+
groupedFieldSet.add(getFieldEntryKey(selection), selection);
|
|
43
84
|
break;
|
|
44
85
|
}
|
|
45
86
|
case import_graphql.Kind.INLINE_FRAGMENT: {
|
|
46
|
-
if (!shouldIncludeNode(
|
|
87
|
+
if (!shouldIncludeNode(exeContext, selection) || !doesFragmentConditionMatch(
|
|
88
|
+
selection,
|
|
89
|
+
runtimeTypeName,
|
|
90
|
+
exeContext.schemaTypes
|
|
91
|
+
)) {
|
|
47
92
|
continue;
|
|
48
93
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
94
|
+
const defer = getDeferValues(exeContext, selection);
|
|
95
|
+
if (defer) {
|
|
96
|
+
const patchFields = new import_AccumulatorMap.AccumulatorMap();
|
|
97
|
+
collectFieldsImpl(
|
|
98
|
+
exeContext,
|
|
99
|
+
runtimeTypeName,
|
|
100
|
+
selection.selectionSet,
|
|
101
|
+
patchFields,
|
|
102
|
+
patches,
|
|
103
|
+
visitedFragmentNames
|
|
104
|
+
);
|
|
105
|
+
patches.push({
|
|
106
|
+
label: defer.label,
|
|
107
|
+
groupedFieldSet: patchFields
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
collectFieldsImpl(
|
|
111
|
+
exeContext,
|
|
112
|
+
runtimeTypeName,
|
|
113
|
+
selection.selectionSet,
|
|
114
|
+
groupedFieldSet,
|
|
115
|
+
patches,
|
|
116
|
+
visitedFragmentNames
|
|
117
|
+
);
|
|
118
|
+
}
|
|
58
119
|
break;
|
|
59
120
|
}
|
|
60
121
|
case import_graphql.Kind.FRAGMENT_SPREAD: {
|
|
61
122
|
const fragName = selection.name.value;
|
|
62
|
-
if (
|
|
123
|
+
if (!shouldIncludeNode(exeContext, selection)) {
|
|
63
124
|
continue;
|
|
64
125
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!fragment || !doesFragmentConditionMatch(fragment, runtimeTypeName, resolvers)) {
|
|
126
|
+
const defer = getDeferValues(exeContext, selection);
|
|
127
|
+
if (visitedFragmentNames.has(fragName) && !defer) {
|
|
68
128
|
continue;
|
|
69
129
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
variableValues,
|
|
130
|
+
const fragment = exeContext.fragments[fragName];
|
|
131
|
+
if (fragment == null || !doesFragmentConditionMatch(
|
|
132
|
+
fragment,
|
|
74
133
|
runtimeTypeName,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
134
|
+
exeContext.schemaTypes
|
|
135
|
+
)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (!defer) {
|
|
139
|
+
visitedFragmentNames.add(fragName);
|
|
140
|
+
}
|
|
141
|
+
if (defer) {
|
|
142
|
+
const patchFields = new import_AccumulatorMap.AccumulatorMap();
|
|
143
|
+
collectFieldsImpl(
|
|
144
|
+
exeContext,
|
|
145
|
+
runtimeTypeName,
|
|
146
|
+
fragment.selectionSet,
|
|
147
|
+
patchFields,
|
|
148
|
+
patches,
|
|
149
|
+
visitedFragmentNames
|
|
150
|
+
);
|
|
151
|
+
patches.push({
|
|
152
|
+
label: defer.label,
|
|
153
|
+
groupedFieldSet: patchFields
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
collectFieldsImpl(
|
|
157
|
+
exeContext,
|
|
158
|
+
runtimeTypeName,
|
|
159
|
+
fragment.selectionSet,
|
|
160
|
+
groupedFieldSet,
|
|
161
|
+
patches,
|
|
162
|
+
visitedFragmentNames
|
|
163
|
+
);
|
|
164
|
+
}
|
|
79
165
|
break;
|
|
80
166
|
}
|
|
81
167
|
}
|
|
82
168
|
}
|
|
83
|
-
return fields;
|
|
84
169
|
}
|
|
85
|
-
function shouldIncludeNode(
|
|
170
|
+
function shouldIncludeNode(exeContext, node) {
|
|
86
171
|
var _a;
|
|
87
172
|
if (!((_a = node.directives) == null ? void 0 : _a.length)) {
|
|
88
173
|
return true;
|
|
89
174
|
}
|
|
90
|
-
const skip = (0, import_values.getDirectiveValues)(
|
|
91
|
-
import_directives.GraphQLSkipDirective,
|
|
92
|
-
node,
|
|
93
|
-
resolvers,
|
|
94
|
-
variableValues
|
|
95
|
-
);
|
|
175
|
+
const skip = (0, import_values.getDirectiveValues)(exeContext, import_directives.GraphQLSkipDirective, node);
|
|
96
176
|
if ((skip == null ? void 0 : skip.if) === true) {
|
|
97
177
|
return false;
|
|
98
178
|
}
|
|
99
|
-
const include = (0, import_values.getDirectiveValues)(
|
|
100
|
-
import_directives.GraphQLIncludeDirective,
|
|
101
|
-
node,
|
|
102
|
-
resolvers,
|
|
103
|
-
variableValues
|
|
104
|
-
);
|
|
179
|
+
const include = (0, import_values.getDirectiveValues)(exeContext, import_directives.GraphQLIncludeDirective, node);
|
|
105
180
|
if ((include == null ? void 0 : include.if) === false) {
|
|
106
181
|
return false;
|
|
107
182
|
}
|
|
108
183
|
return true;
|
|
109
184
|
}
|
|
110
|
-
function doesFragmentConditionMatch(fragment, typeName,
|
|
185
|
+
function doesFragmentConditionMatch(fragment, typeName, schemaFragment) {
|
|
111
186
|
const typeConditionNode = fragment.typeCondition;
|
|
112
187
|
if (!typeConditionNode) {
|
|
113
188
|
return true;
|
|
114
189
|
}
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
190
|
+
const conditionalTypeName = typeConditionNode.name.value;
|
|
191
|
+
if (conditionalTypeName === typeName) {
|
|
117
192
|
return true;
|
|
118
193
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
function getSubTypes(resolvers, abstractTypes, conditionalType) {
|
|
123
|
-
const resolver = resolvers[conditionalType];
|
|
124
|
-
if ((0, import_definition.isInterfaceResolverType)(resolver)) {
|
|
125
|
-
const result = resolver.__implementedBy.reduce(
|
|
126
|
-
(acc, item) => {
|
|
127
|
-
if (!abstractTypes.has(item)) {
|
|
128
|
-
const newTypes = /* @__PURE__ */ new Set([...abstractTypes, item]);
|
|
129
|
-
acc.push(...abstractTypes, ...getSubTypes(resolvers, newTypes, item));
|
|
130
|
-
}
|
|
131
|
-
return acc;
|
|
132
|
-
},
|
|
133
|
-
[]
|
|
134
|
-
);
|
|
135
|
-
return /* @__PURE__ */ new Set([...result]);
|
|
194
|
+
if (schemaFragment.isAbstractType(conditionalTypeName)) {
|
|
195
|
+
return schemaFragment.isSubType(conditionalTypeName, typeName);
|
|
136
196
|
}
|
|
137
|
-
|
|
138
|
-
const result = resolver.__types.reduce((acc, item) => {
|
|
139
|
-
if (!abstractTypes.has(item)) {
|
|
140
|
-
const newTypes = /* @__PURE__ */ new Set([...abstractTypes, item]);
|
|
141
|
-
acc.push(...abstractTypes, ...getSubTypes(resolvers, newTypes, item));
|
|
142
|
-
}
|
|
143
|
-
return acc;
|
|
144
|
-
}, []);
|
|
145
|
-
return /* @__PURE__ */ new Set([...result]);
|
|
146
|
-
}
|
|
147
|
-
return abstractTypes;
|
|
197
|
+
return false;
|
|
148
198
|
}
|
|
149
199
|
function getFieldEntryKey(node) {
|
|
150
200
|
return node.alias ? node.alias.value : node.name.value;
|
|
151
201
|
}
|
|
202
|
+
function getDeferValues(exeContext, node) {
|
|
203
|
+
const defer = (0, import_values.getDirectiveValues)(exeContext, import_directives.GraphQLDeferDirective, node);
|
|
204
|
+
if (!defer) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (defer.if === false) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
(0, import_invariant.default)(
|
|
211
|
+
exeContext.operation.operation !== "subscription",
|
|
212
|
+
"`@defer` directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`."
|
|
213
|
+
);
|
|
214
|
+
return {
|
|
215
|
+
label: typeof defer.label === "string" ? defer.label : void 0
|
|
216
|
+
};
|
|
217
|
+
}
|
package/lib/collectFields.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/collectFields.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import {\n Kind,\n FieldNode,\n FragmentDefinitionNode,\n FragmentSpreadNode,\n InlineFragmentNode,\n SelectionNode,\n SelectionSetNode,\n} from \"graphql\";\nimport { getDirectiveValues } from \"./values\";\nimport {\n GraphQLSkipDirective,\n GraphQLIncludeDirective,\n GraphQLDeferDirective,\n} from \"./schema/directives\";\n\nimport { AccumulatorMap } from \"./jsutils/AccumulatorMap\";\nimport invariant from \"invariant\";\nimport { ExecutionContext } from \"./executeWithoutSchema\";\nimport { SchemaFragment } from \"./schema/fragment\";\n\nexport type FieldGroup = ReadonlyArray<FieldNode>;\n\nexport type GroupedFieldSet = Map<string, FieldGroup>;\n\nexport interface PatchFields {\n label: string | undefined;\n groupedFieldSet: GroupedFieldSet;\n}\n\nexport interface FieldsAndPatches {\n groupedFieldSet: GroupedFieldSet;\n patches: Array<PatchFields>;\n}\n\n/**\n * Given a selectionSet, collects all of the fields and returns them.\n *\n * CollectFields requires the \"runtime type\" of an object. For a field that\n * returns an Interface or Union type, the \"runtime type\" will be the actual\n * object type returned by that field.\n *\n * @internal\n */\nexport function collectFields(\n exeContext: ExecutionContext,\n runtimeTypeName: string,\n): FieldsAndPatches {\n const { operation } = exeContext;\n const groupedFieldSet = new AccumulatorMap<string, FieldNode>();\n const patches: Array<PatchFields> = [];\n collectFieldsImpl(\n exeContext,\n runtimeTypeName,\n operation.selectionSet,\n groupedFieldSet,\n patches,\n new Set(),\n );\n return { groupedFieldSet, patches };\n}\n\n/**\n * Given an array of field nodes, collects all of the subfields of the passed\n * in fields, and returns them at the end.\n *\n * CollectSubFields requires the \"return type\" of an object. For a field that\n * returns an Interface or Union type, the \"return type\" will be the actual\n * object type returned by that field.\n *\n * @internal\n */\n// eslint-disable-next-line max-params\nexport function collectSubfields(\n exeContext: ExecutionContext,\n returnTypeName: string,\n fieldGroup: FieldGroup,\n): FieldsAndPatches {\n const subGroupedFieldSet = new AccumulatorMap<string, FieldNode>();\n const visitedFragmentNames = new Set<string>();\n\n const subPatches: Array<PatchFields> = [];\n const subFieldsAndPatches = {\n groupedFieldSet: subGroupedFieldSet,\n patches: subPatches,\n };\n\n for (const node of fieldGroup) {\n if (node.selectionSet) {\n collectFieldsImpl(\n exeContext,\n returnTypeName,\n node.selectionSet,\n subGroupedFieldSet,\n subPatches,\n visitedFragmentNames,\n );\n }\n }\n return subFieldsAndPatches;\n}\n\n// eslint-disable-next-line max-params\nfunction collectFieldsImpl(\n exeContext: ExecutionContext,\n runtimeTypeName: string,\n selectionSet: SelectionSetNode,\n groupedFieldSet: AccumulatorMap<string, FieldNode>,\n patches: Array<PatchFields>,\n visitedFragmentNames: Set<string>,\n): void {\n for (const selection of selectionSet.selections) {\n switch (selection.kind) {\n case Kind.FIELD: {\n if (!shouldIncludeNode(exeContext, selection)) {\n continue;\n }\n groupedFieldSet.add(getFieldEntryKey(selection), selection);\n break;\n }\n case Kind.INLINE_FRAGMENT: {\n if (\n !shouldIncludeNode(exeContext, selection) ||\n !doesFragmentConditionMatch(\n selection,\n runtimeTypeName,\n exeContext.schemaTypes,\n )\n ) {\n continue;\n }\n\n const defer = getDeferValues(exeContext, selection);\n\n if (defer) {\n const patchFields = new AccumulatorMap<string, FieldNode>();\n collectFieldsImpl(\n exeContext,\n runtimeTypeName,\n selection.selectionSet,\n patchFields,\n patches,\n visitedFragmentNames,\n );\n patches.push({\n label: defer.label,\n groupedFieldSet: patchFields,\n });\n } else {\n collectFieldsImpl(\n exeContext,\n runtimeTypeName,\n selection.selectionSet,\n groupedFieldSet,\n patches,\n visitedFragmentNames,\n );\n }\n break;\n }\n case Kind.FRAGMENT_SPREAD: {\n const fragName = selection.name.value;\n\n if (!shouldIncludeNode(exeContext, selection)) {\n continue;\n }\n\n const defer = getDeferValues(exeContext, selection);\n if (visitedFragmentNames.has(fragName) && !defer) {\n continue;\n }\n\n const fragment = exeContext.fragments[fragName];\n if (\n fragment == null ||\n !doesFragmentConditionMatch(\n fragment,\n runtimeTypeName,\n exeContext.schemaTypes,\n )\n ) {\n continue;\n }\n\n if (!defer) {\n visitedFragmentNames.add(fragName);\n }\n\n if (defer) {\n const patchFields = new AccumulatorMap<string, FieldNode>();\n collectFieldsImpl(\n exeContext,\n runtimeTypeName,\n fragment.selectionSet,\n patchFields,\n patches,\n visitedFragmentNames,\n );\n patches.push({\n label: defer.label,\n groupedFieldSet: patchFields,\n });\n } else {\n collectFieldsImpl(\n exeContext,\n runtimeTypeName,\n fragment.selectionSet,\n groupedFieldSet,\n patches,\n visitedFragmentNames,\n );\n }\n break;\n }\n }\n }\n}\n\n/**\n * Determines if a field should be included based on the @include and @skip\n * directives, where @skip has higher precedence than @include.\n */\nfunction shouldIncludeNode(\n exeContext: ExecutionContext,\n node: SelectionNode,\n): boolean {\n if (!node.directives?.length) {\n return true;\n }\n\n const skip = getDirectiveValues(exeContext, GraphQLSkipDirective, node);\n if (skip?.if === true) {\n return false;\n }\n\n const include = getDirectiveValues(exeContext, GraphQLIncludeDirective, node);\n if (include?.if === false) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Determines if a fragment is applicable to the given type.\n */\nfunction doesFragmentConditionMatch(\n fragment: FragmentDefinitionNode | InlineFragmentNode,\n typeName: string,\n // resolvers: Resolvers,\n schemaFragment: SchemaFragment,\n): boolean {\n const typeConditionNode = fragment.typeCondition;\n if (!typeConditionNode) {\n return true;\n }\n\n const conditionalTypeName = typeConditionNode.name.value;\n\n if (conditionalTypeName === typeName) {\n return true;\n }\n if (schemaFragment.isAbstractType(conditionalTypeName)) {\n return schemaFragment.isSubType(conditionalTypeName, typeName);\n }\n return false;\n}\n\n/**\n * Implements the logic to compute the key of a given field's entry\n */\nfunction getFieldEntryKey(node: FieldNode): string {\n return node.alias ? node.alias.value : node.name.value;\n}\n\n/**\n * Returns an object containing the `@defer` arguments if a field should be\n * deferred based on the experimental flag, defer directive present and\n * not disabled by the \"if\" argument.\n */\nfunction getDeferValues(\n exeContext: ExecutionContext,\n node: FragmentSpreadNode | InlineFragmentNode,\n): undefined | { label: string | undefined } {\n const defer = getDirectiveValues(exeContext, GraphQLDeferDirective, node);\n\n if (!defer) {\n return;\n }\n\n if (defer.if === false) {\n return;\n }\n\n invariant(\n exeContext.operation.operation !== \"subscription\",\n \"`@defer` directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.\",\n );\n\n return {\n label: typeof defer.label === \"string\" ? defer.label : undefined,\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AACP,oBAAmC;AACnC,wBAIO;AAEP,4BAA+B;AAC/B,uBAAsB;AA2Bf,SAAS,cACd,YACA,iBACkB;AAClB,QAAM,EAAE,UAAU,IAAI;AACtB,QAAM,kBAAkB,IAAI,qCAAkC;AAC9D,QAAM,UAA8B,CAAC;AACrC;AAAA,IACE;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,oBAAI,IAAI;AAAA,EACV;AACA,SAAO,EAAE,iBAAiB,QAAQ;AACpC;AAaO,SAAS,iBACd,YACA,gBACA,YACkB;AAClB,QAAM,qBAAqB,IAAI,qCAAkC;AACjE,QAAM,uBAAuB,oBA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