@gqloom/core 0.12.1 → 0.14.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/dist/{chunk-CTAAG5j7.js → chunk-Bp6m_JJh.js} +1 -1
- package/dist/context.cjs +9 -9
- package/dist/context.d.cts +5 -6
- package/dist/context.d.ts +5 -6
- package/dist/context.js +1 -1
- package/dist/{index-sGKC4BRu.d.ts → index-BdLdDytD.d.ts} +433 -404
- package/dist/{index-BxqR3YsC.d.cts → index-C26E_cfW.d.cts} +433 -404
- package/dist/index.cjs +440 -429
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +409 -399
- package/dist/{context-BxqO4Eg9.js → parse-resolving-fields-CH8rJgks.js} +102 -79
- package/dist/{context-DshDoxiE.cjs → parse-resolving-fields-Czn0O39L.cjs} +106 -77
- package/package.json +1 -1
|
@@ -1,10 +1,75 @@
|
|
|
1
|
-
import { __export } from "./chunk-
|
|
1
|
+
import { t as __export } from "./chunk-Bp6m_JJh.js";
|
|
2
2
|
import { Kind, isInterfaceType, isListType, isNonNullType, isObjectType } from "graphql";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/constants.ts
|
|
5
5
|
const DERIVED_DEPENDENCIES = "loom.derived-from-dependencies";
|
|
6
6
|
const AUTO_ALIASING = "__gqloom_auto_aliasing";
|
|
7
7
|
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/utils/symbols.ts
|
|
10
|
+
var symbols_exports = /* @__PURE__ */ __export({
|
|
11
|
+
CONTEXT_MAP_KEY: () => CONTEXT_MAP_KEY,
|
|
12
|
+
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
13
|
+
GET_GRAPHQL_ARGUMENT_CONFIG: () => GET_GRAPHQL_ARGUMENT_CONFIG,
|
|
14
|
+
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
15
|
+
IS_RESOLVER: () => IS_RESOLVER,
|
|
16
|
+
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
17
|
+
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* The symbol to get GraphQL type for schema
|
|
21
|
+
*/
|
|
22
|
+
const GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
23
|
+
/**
|
|
24
|
+
* The symbol to get GraphQL argument config for schema
|
|
25
|
+
*/
|
|
26
|
+
const GET_GRAPHQL_ARGUMENT_CONFIG = Symbol.for("gqloom.get_graphql_argument_config");
|
|
27
|
+
/**
|
|
28
|
+
* The symbol to get and store weaver config
|
|
29
|
+
*/
|
|
30
|
+
const WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
31
|
+
/**
|
|
32
|
+
* The symbol to get resolver options
|
|
33
|
+
*/
|
|
34
|
+
const RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
35
|
+
/**
|
|
36
|
+
* The symbol to check if an object is a resolver
|
|
37
|
+
*/
|
|
38
|
+
const IS_RESOLVER = Symbol.for("gqloom.is-resolver");
|
|
39
|
+
/**
|
|
40
|
+
* The symbol to assign a WeakMap to an object
|
|
41
|
+
*/
|
|
42
|
+
const CONTEXT_MAP_KEY = Symbol.for("gqloom.context-map");
|
|
43
|
+
/**
|
|
44
|
+
* Set fields to be hidden
|
|
45
|
+
*/
|
|
46
|
+
const FIELD_HIDDEN = false;
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/utils/context.ts
|
|
50
|
+
/**
|
|
51
|
+
* Create an empty memoization payload for the resolver
|
|
52
|
+
* @returns the empty memoization payload
|
|
53
|
+
*/
|
|
54
|
+
function onlyMemoization() {
|
|
55
|
+
return {
|
|
56
|
+
memoization: /* @__PURE__ */ new WeakMap(),
|
|
57
|
+
isMemoization: true
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function isOnlyMemoryPayload(payload) {
|
|
61
|
+
return payload.isMemoization === true;
|
|
62
|
+
}
|
|
63
|
+
function getMemoizationMap(payload) {
|
|
64
|
+
if (isOnlyMemoryPayload(payload)) return payload.memoization;
|
|
65
|
+
if (typeof payload.context === "undefined") Object.defineProperty(payload, "context", { value: {} });
|
|
66
|
+
return assignContextMap(payload.context);
|
|
67
|
+
}
|
|
68
|
+
function assignContextMap(target) {
|
|
69
|
+
target[CONTEXT_MAP_KEY] ??= /* @__PURE__ */ new WeakMap();
|
|
70
|
+
return target[CONTEXT_MAP_KEY];
|
|
71
|
+
}
|
|
72
|
+
|
|
8
73
|
//#endregion
|
|
9
74
|
//#region src/utils/type.ts
|
|
10
75
|
function unwrapType(gqlType) {
|
|
@@ -19,12 +84,17 @@ function unwrapType(gqlType) {
|
|
|
19
84
|
* Analyzes and processes field resolution in a GraphQL query deeply.
|
|
20
85
|
*
|
|
21
86
|
* @param payload - The resolver payload containing the current field resolution context
|
|
22
|
-
* @param
|
|
87
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = Infinity)
|
|
23
88
|
* @returns A map of field paths to their resolving fields
|
|
24
89
|
*/
|
|
25
|
-
function getDeepResolvingFields(payload,
|
|
90
|
+
function getDeepResolvingFields(payload, options) {
|
|
91
|
+
const resolvedDepth = options?.maxDepth ?? Infinity;
|
|
92
|
+
const mergedOptions = {
|
|
93
|
+
...options,
|
|
94
|
+
maxDepth: resolvedDepth
|
|
95
|
+
};
|
|
26
96
|
const result = /* @__PURE__ */ new Map();
|
|
27
|
-
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info,
|
|
97
|
+
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info, mergedOptions);
|
|
28
98
|
const rootType = unwrapType(payload.info.returnType);
|
|
29
99
|
for (const [path, requestedFields] of requestedFieldsByPath.entries()) {
|
|
30
100
|
let currentType = rootType;
|
|
@@ -80,10 +150,14 @@ function getDeepResolvingFields(payload, maxDepth = Infinity) {
|
|
|
80
150
|
* Analyzes and processes field resolution in a GraphQL query.
|
|
81
151
|
*
|
|
82
152
|
* @param payload - The resolver payload containing the current field resolution context
|
|
153
|
+
* @param options - Additional parsing options (e.g., includeIntrospection; fixed maxDepth = 1)
|
|
83
154
|
* @returns An object containing sets of different field types
|
|
84
155
|
*/
|
|
85
|
-
function getResolvingFields(payload) {
|
|
86
|
-
const requestedFields = parseResolvingFields(payload.info
|
|
156
|
+
function getResolvingFields(payload, options) {
|
|
157
|
+
const requestedFields = parseResolvingFields(payload.info, {
|
|
158
|
+
...options,
|
|
159
|
+
maxDepth: 1
|
|
160
|
+
});
|
|
87
161
|
const derivedFields = /* @__PURE__ */ new Set();
|
|
88
162
|
const derivedDependencies = /* @__PURE__ */ new Set();
|
|
89
163
|
const resolvingObject = unwrapType(payload.info.returnType);
|
|
@@ -116,11 +190,16 @@ function getResolvingFields(payload) {
|
|
|
116
190
|
* Supports @include, @skip directives, fragments, and variables.
|
|
117
191
|
*
|
|
118
192
|
* @param info - The GraphQL resolve info object containing the query information
|
|
119
|
-
* @param
|
|
193
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = 1)
|
|
120
194
|
* @returns A Set of field paths
|
|
121
195
|
*/
|
|
122
|
-
function parseResolvingFields(info,
|
|
123
|
-
|
|
196
|
+
function parseResolvingFields(info, options) {
|
|
197
|
+
const resolvedDepth = options?.maxDepth ?? 1;
|
|
198
|
+
const mergedOptions = {
|
|
199
|
+
...options,
|
|
200
|
+
maxDepth: resolvedDepth
|
|
201
|
+
};
|
|
202
|
+
return ResolvingFieldsParser.parse(info, mergedOptions);
|
|
124
203
|
}
|
|
125
204
|
/**
|
|
126
205
|
* Class responsible for parsing GraphQL resolve info to extract all requested fields.
|
|
@@ -132,17 +211,20 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
132
211
|
visitedFragments = /* @__PURE__ */ new Set();
|
|
133
212
|
/** The GraphQL resolve info object */
|
|
134
213
|
info;
|
|
135
|
-
/**
|
|
136
|
-
|
|
137
|
-
static parse(info,
|
|
138
|
-
return new ResolvingFieldsParser(info,
|
|
214
|
+
/** Options controlling parsing behavior */
|
|
215
|
+
options;
|
|
216
|
+
static parse(info, options) {
|
|
217
|
+
return new ResolvingFieldsParser(info, options).parse();
|
|
139
218
|
}
|
|
140
|
-
static parseDeep(info,
|
|
141
|
-
return new ResolvingFieldsParser(info,
|
|
219
|
+
static parseDeep(info, options) {
|
|
220
|
+
return new ResolvingFieldsParser(info, options).parseDeep();
|
|
142
221
|
}
|
|
143
|
-
constructor(info,
|
|
222
|
+
constructor(info, options) {
|
|
144
223
|
this.info = info;
|
|
145
|
-
this.
|
|
224
|
+
this.options = {
|
|
225
|
+
maxDepth: options?.maxDepth ?? Infinity,
|
|
226
|
+
includeIntrospection: options?.includeIntrospection ?? false
|
|
227
|
+
};
|
|
146
228
|
for (const fieldNode of this.info.fieldNodes) this.collectFields(fieldNode.selectionSet, "", 0);
|
|
147
229
|
}
|
|
148
230
|
/**
|
|
@@ -174,7 +256,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
174
256
|
* @param currentDepth - Current depth of recursion
|
|
175
257
|
*/
|
|
176
258
|
collectFields(selectionSet, parentPath = "", currentDepth = 0) {
|
|
177
|
-
if (!selectionSet?.selections.length || currentDepth >= this.maxDepth) return;
|
|
259
|
+
if (!selectionSet?.selections.length || currentDepth >= this.options.maxDepth) return;
|
|
178
260
|
if (!this.fields.has(parentPath)) this.fields.set(parentPath, /* @__PURE__ */ new Set());
|
|
179
261
|
const currentFields = this.fields.get(parentPath);
|
|
180
262
|
for (const selection of selectionSet.selections) {
|
|
@@ -182,6 +264,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
182
264
|
switch (selection.kind) {
|
|
183
265
|
case Kind.FIELD: {
|
|
184
266
|
const fieldName = selection.name.value;
|
|
267
|
+
if (!this.options.includeIntrospection && fieldName.startsWith("__")) break;
|
|
185
268
|
currentFields.add(fieldName);
|
|
186
269
|
if (selection.selectionSet != null) {
|
|
187
270
|
const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
|
|
@@ -239,64 +322,4 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
239
322
|
};
|
|
240
323
|
|
|
241
324
|
//#endregion
|
|
242
|
-
|
|
243
|
-
var symbols_exports = /* @__PURE__ */ __export({
|
|
244
|
-
CONTEXT_MAP_KEY: () => CONTEXT_MAP_KEY,
|
|
245
|
-
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
246
|
-
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
247
|
-
IS_RESOLVER: () => IS_RESOLVER,
|
|
248
|
-
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
249
|
-
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
250
|
-
});
|
|
251
|
-
/**
|
|
252
|
-
* The symbol to get GraphQL type for schema
|
|
253
|
-
*/
|
|
254
|
-
const GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
255
|
-
/**
|
|
256
|
-
* The symbol to get and store weaver config
|
|
257
|
-
*/
|
|
258
|
-
const WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
259
|
-
/**
|
|
260
|
-
* The symbol to get resolver options
|
|
261
|
-
*/
|
|
262
|
-
const RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
263
|
-
/**
|
|
264
|
-
* The symbol to check if an object is a resolver
|
|
265
|
-
*/
|
|
266
|
-
const IS_RESOLVER = Symbol.for("gqloom.is-resolver");
|
|
267
|
-
/**
|
|
268
|
-
* The symbol to assign a WeakMap to an object
|
|
269
|
-
*/
|
|
270
|
-
const CONTEXT_MAP_KEY = Symbol.for("gqloom.context-map");
|
|
271
|
-
/**
|
|
272
|
-
* Set fields to be hidden
|
|
273
|
-
*/
|
|
274
|
-
const FIELD_HIDDEN = false;
|
|
275
|
-
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/utils/context.ts
|
|
278
|
-
/**
|
|
279
|
-
* Create an empty memoization payload for the resolver
|
|
280
|
-
* @returns the empty memoization payload
|
|
281
|
-
*/
|
|
282
|
-
function onlyMemoization() {
|
|
283
|
-
return {
|
|
284
|
-
memoization: /* @__PURE__ */ new WeakMap(),
|
|
285
|
-
isMemoization: true
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function isOnlyMemoryPayload(payload) {
|
|
289
|
-
return payload.isMemoization === true;
|
|
290
|
-
}
|
|
291
|
-
function getMemoizationMap(payload) {
|
|
292
|
-
if (isOnlyMemoryPayload(payload)) return payload.memoization;
|
|
293
|
-
if (typeof payload.context === "undefined") Object.defineProperty(payload, "context", { value: {} });
|
|
294
|
-
return assignContextMap(payload.context);
|
|
295
|
-
}
|
|
296
|
-
function assignContextMap(target) {
|
|
297
|
-
target[CONTEXT_MAP_KEY] ??= /* @__PURE__ */ new WeakMap();
|
|
298
|
-
return target[CONTEXT_MAP_KEY];
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
//#endregion
|
|
302
|
-
export { AUTO_ALIASING, DERIVED_DEPENDENCIES, FIELD_HIDDEN, GET_GRAPHQL_TYPE, IS_RESOLVER, WEAVER_CONFIG, assignContextMap, getDeepResolvingFields, getMemoizationMap, getResolvingFields, isOnlyMemoryPayload, onlyMemoization, parseResolvingFields, symbols_exports };
|
|
325
|
+
export { getMemoizationMap as a, FIELD_HIDDEN as c, IS_RESOLVER as d, WEAVER_CONFIG as f, DERIVED_DEPENDENCIES as h, assignContextMap as i, GET_GRAPHQL_ARGUMENT_CONFIG as l, AUTO_ALIASING as m, getResolvingFields as n, isOnlyMemoryPayload as o, symbols_exports as p, parseResolvingFields as r, onlyMemoization as s, getDeepResolvingFields as t, GET_GRAPHQL_TYPE as u };
|
|
@@ -36,6 +36,71 @@ graphql = __toESM(graphql);
|
|
|
36
36
|
const DERIVED_DEPENDENCIES = "loom.derived-from-dependencies";
|
|
37
37
|
const AUTO_ALIASING = "__gqloom_auto_aliasing";
|
|
38
38
|
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/utils/symbols.ts
|
|
41
|
+
var symbols_exports = /* @__PURE__ */ __export({
|
|
42
|
+
CONTEXT_MAP_KEY: () => CONTEXT_MAP_KEY,
|
|
43
|
+
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
44
|
+
GET_GRAPHQL_ARGUMENT_CONFIG: () => GET_GRAPHQL_ARGUMENT_CONFIG,
|
|
45
|
+
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
46
|
+
IS_RESOLVER: () => IS_RESOLVER,
|
|
47
|
+
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
48
|
+
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* The symbol to get GraphQL type for schema
|
|
52
|
+
*/
|
|
53
|
+
const GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
54
|
+
/**
|
|
55
|
+
* The symbol to get GraphQL argument config for schema
|
|
56
|
+
*/
|
|
57
|
+
const GET_GRAPHQL_ARGUMENT_CONFIG = Symbol.for("gqloom.get_graphql_argument_config");
|
|
58
|
+
/**
|
|
59
|
+
* The symbol to get and store weaver config
|
|
60
|
+
*/
|
|
61
|
+
const WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
62
|
+
/**
|
|
63
|
+
* The symbol to get resolver options
|
|
64
|
+
*/
|
|
65
|
+
const RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
66
|
+
/**
|
|
67
|
+
* The symbol to check if an object is a resolver
|
|
68
|
+
*/
|
|
69
|
+
const IS_RESOLVER = Symbol.for("gqloom.is-resolver");
|
|
70
|
+
/**
|
|
71
|
+
* The symbol to assign a WeakMap to an object
|
|
72
|
+
*/
|
|
73
|
+
const CONTEXT_MAP_KEY = Symbol.for("gqloom.context-map");
|
|
74
|
+
/**
|
|
75
|
+
* Set fields to be hidden
|
|
76
|
+
*/
|
|
77
|
+
const FIELD_HIDDEN = false;
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/utils/context.ts
|
|
81
|
+
/**
|
|
82
|
+
* Create an empty memoization payload for the resolver
|
|
83
|
+
* @returns the empty memoization payload
|
|
84
|
+
*/
|
|
85
|
+
function onlyMemoization() {
|
|
86
|
+
return {
|
|
87
|
+
memoization: /* @__PURE__ */ new WeakMap(),
|
|
88
|
+
isMemoization: true
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function isOnlyMemoryPayload(payload) {
|
|
92
|
+
return payload.isMemoization === true;
|
|
93
|
+
}
|
|
94
|
+
function getMemoizationMap(payload) {
|
|
95
|
+
if (isOnlyMemoryPayload(payload)) return payload.memoization;
|
|
96
|
+
if (typeof payload.context === "undefined") Object.defineProperty(payload, "context", { value: {} });
|
|
97
|
+
return assignContextMap(payload.context);
|
|
98
|
+
}
|
|
99
|
+
function assignContextMap(target) {
|
|
100
|
+
target[CONTEXT_MAP_KEY] ??= /* @__PURE__ */ new WeakMap();
|
|
101
|
+
return target[CONTEXT_MAP_KEY];
|
|
102
|
+
}
|
|
103
|
+
|
|
39
104
|
//#endregion
|
|
40
105
|
//#region src/utils/type.ts
|
|
41
106
|
function unwrapType(gqlType) {
|
|
@@ -50,12 +115,17 @@ function unwrapType(gqlType) {
|
|
|
50
115
|
* Analyzes and processes field resolution in a GraphQL query deeply.
|
|
51
116
|
*
|
|
52
117
|
* @param payload - The resolver payload containing the current field resolution context
|
|
53
|
-
* @param
|
|
118
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = Infinity)
|
|
54
119
|
* @returns A map of field paths to their resolving fields
|
|
55
120
|
*/
|
|
56
|
-
function getDeepResolvingFields(payload,
|
|
121
|
+
function getDeepResolvingFields(payload, options) {
|
|
122
|
+
const resolvedDepth = options?.maxDepth ?? Infinity;
|
|
123
|
+
const mergedOptions = {
|
|
124
|
+
...options,
|
|
125
|
+
maxDepth: resolvedDepth
|
|
126
|
+
};
|
|
57
127
|
const result = /* @__PURE__ */ new Map();
|
|
58
|
-
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info,
|
|
128
|
+
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info, mergedOptions);
|
|
59
129
|
const rootType = unwrapType(payload.info.returnType);
|
|
60
130
|
for (const [path, requestedFields] of requestedFieldsByPath.entries()) {
|
|
61
131
|
let currentType = rootType;
|
|
@@ -111,10 +181,14 @@ function getDeepResolvingFields(payload, maxDepth = Infinity) {
|
|
|
111
181
|
* Analyzes and processes field resolution in a GraphQL query.
|
|
112
182
|
*
|
|
113
183
|
* @param payload - The resolver payload containing the current field resolution context
|
|
184
|
+
* @param options - Additional parsing options (e.g., includeIntrospection; fixed maxDepth = 1)
|
|
114
185
|
* @returns An object containing sets of different field types
|
|
115
186
|
*/
|
|
116
|
-
function getResolvingFields(payload) {
|
|
117
|
-
const requestedFields = parseResolvingFields(payload.info
|
|
187
|
+
function getResolvingFields(payload, options) {
|
|
188
|
+
const requestedFields = parseResolvingFields(payload.info, {
|
|
189
|
+
...options,
|
|
190
|
+
maxDepth: 1
|
|
191
|
+
});
|
|
118
192
|
const derivedFields = /* @__PURE__ */ new Set();
|
|
119
193
|
const derivedDependencies = /* @__PURE__ */ new Set();
|
|
120
194
|
const resolvingObject = unwrapType(payload.info.returnType);
|
|
@@ -147,11 +221,16 @@ function getResolvingFields(payload) {
|
|
|
147
221
|
* Supports @include, @skip directives, fragments, and variables.
|
|
148
222
|
*
|
|
149
223
|
* @param info - The GraphQL resolve info object containing the query information
|
|
150
|
-
* @param
|
|
224
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = 1)
|
|
151
225
|
* @returns A Set of field paths
|
|
152
226
|
*/
|
|
153
|
-
function parseResolvingFields(info,
|
|
154
|
-
|
|
227
|
+
function parseResolvingFields(info, options) {
|
|
228
|
+
const resolvedDepth = options?.maxDepth ?? 1;
|
|
229
|
+
const mergedOptions = {
|
|
230
|
+
...options,
|
|
231
|
+
maxDepth: resolvedDepth
|
|
232
|
+
};
|
|
233
|
+
return ResolvingFieldsParser.parse(info, mergedOptions);
|
|
155
234
|
}
|
|
156
235
|
/**
|
|
157
236
|
* Class responsible for parsing GraphQL resolve info to extract all requested fields.
|
|
@@ -163,17 +242,20 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
163
242
|
visitedFragments = /* @__PURE__ */ new Set();
|
|
164
243
|
/** The GraphQL resolve info object */
|
|
165
244
|
info;
|
|
166
|
-
/**
|
|
167
|
-
|
|
168
|
-
static parse(info,
|
|
169
|
-
return new ResolvingFieldsParser(info,
|
|
245
|
+
/** Options controlling parsing behavior */
|
|
246
|
+
options;
|
|
247
|
+
static parse(info, options) {
|
|
248
|
+
return new ResolvingFieldsParser(info, options).parse();
|
|
170
249
|
}
|
|
171
|
-
static parseDeep(info,
|
|
172
|
-
return new ResolvingFieldsParser(info,
|
|
250
|
+
static parseDeep(info, options) {
|
|
251
|
+
return new ResolvingFieldsParser(info, options).parseDeep();
|
|
173
252
|
}
|
|
174
|
-
constructor(info,
|
|
253
|
+
constructor(info, options) {
|
|
175
254
|
this.info = info;
|
|
176
|
-
this.
|
|
255
|
+
this.options = {
|
|
256
|
+
maxDepth: options?.maxDepth ?? Infinity,
|
|
257
|
+
includeIntrospection: options?.includeIntrospection ?? false
|
|
258
|
+
};
|
|
177
259
|
for (const fieldNode of this.info.fieldNodes) this.collectFields(fieldNode.selectionSet, "", 0);
|
|
178
260
|
}
|
|
179
261
|
/**
|
|
@@ -205,7 +287,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
205
287
|
* @param currentDepth - Current depth of recursion
|
|
206
288
|
*/
|
|
207
289
|
collectFields(selectionSet, parentPath = "", currentDepth = 0) {
|
|
208
|
-
if (!selectionSet?.selections.length || currentDepth >= this.maxDepth) return;
|
|
290
|
+
if (!selectionSet?.selections.length || currentDepth >= this.options.maxDepth) return;
|
|
209
291
|
if (!this.fields.has(parentPath)) this.fields.set(parentPath, /* @__PURE__ */ new Set());
|
|
210
292
|
const currentFields = this.fields.get(parentPath);
|
|
211
293
|
for (const selection of selectionSet.selections) {
|
|
@@ -213,6 +295,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
213
295
|
switch (selection.kind) {
|
|
214
296
|
case graphql.Kind.FIELD: {
|
|
215
297
|
const fieldName = selection.name.value;
|
|
298
|
+
if (!this.options.includeIntrospection && fieldName.startsWith("__")) break;
|
|
216
299
|
currentFields.add(fieldName);
|
|
217
300
|
if (selection.selectionSet != null) {
|
|
218
301
|
const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
|
|
@@ -269,66 +352,6 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
269
352
|
}
|
|
270
353
|
};
|
|
271
354
|
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/utils/symbols.ts
|
|
274
|
-
var symbols_exports = /* @__PURE__ */ __export({
|
|
275
|
-
CONTEXT_MAP_KEY: () => CONTEXT_MAP_KEY,
|
|
276
|
-
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
277
|
-
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
278
|
-
IS_RESOLVER: () => IS_RESOLVER,
|
|
279
|
-
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
280
|
-
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
281
|
-
});
|
|
282
|
-
/**
|
|
283
|
-
* The symbol to get GraphQL type for schema
|
|
284
|
-
*/
|
|
285
|
-
const GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
286
|
-
/**
|
|
287
|
-
* The symbol to get and store weaver config
|
|
288
|
-
*/
|
|
289
|
-
const WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
290
|
-
/**
|
|
291
|
-
* The symbol to get resolver options
|
|
292
|
-
*/
|
|
293
|
-
const RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
294
|
-
/**
|
|
295
|
-
* The symbol to check if an object is a resolver
|
|
296
|
-
*/
|
|
297
|
-
const IS_RESOLVER = Symbol.for("gqloom.is-resolver");
|
|
298
|
-
/**
|
|
299
|
-
* The symbol to assign a WeakMap to an object
|
|
300
|
-
*/
|
|
301
|
-
const CONTEXT_MAP_KEY = Symbol.for("gqloom.context-map");
|
|
302
|
-
/**
|
|
303
|
-
* Set fields to be hidden
|
|
304
|
-
*/
|
|
305
|
-
const FIELD_HIDDEN = false;
|
|
306
|
-
|
|
307
|
-
//#endregion
|
|
308
|
-
//#region src/utils/context.ts
|
|
309
|
-
/**
|
|
310
|
-
* Create an empty memoization payload for the resolver
|
|
311
|
-
* @returns the empty memoization payload
|
|
312
|
-
*/
|
|
313
|
-
function onlyMemoization() {
|
|
314
|
-
return {
|
|
315
|
-
memoization: /* @__PURE__ */ new WeakMap(),
|
|
316
|
-
isMemoization: true
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function isOnlyMemoryPayload(payload) {
|
|
320
|
-
return payload.isMemoization === true;
|
|
321
|
-
}
|
|
322
|
-
function getMemoizationMap(payload) {
|
|
323
|
-
if (isOnlyMemoryPayload(payload)) return payload.memoization;
|
|
324
|
-
if (typeof payload.context === "undefined") Object.defineProperty(payload, "context", { value: {} });
|
|
325
|
-
return assignContextMap(payload.context);
|
|
326
|
-
}
|
|
327
|
-
function assignContextMap(target) {
|
|
328
|
-
target[CONTEXT_MAP_KEY] ??= /* @__PURE__ */ new WeakMap();
|
|
329
|
-
return target[CONTEXT_MAP_KEY];
|
|
330
|
-
}
|
|
331
|
-
|
|
332
355
|
//#endregion
|
|
333
356
|
Object.defineProperty(exports, 'AUTO_ALIASING', {
|
|
334
357
|
enumerable: true,
|
|
@@ -348,6 +371,12 @@ Object.defineProperty(exports, 'FIELD_HIDDEN', {
|
|
|
348
371
|
return FIELD_HIDDEN;
|
|
349
372
|
}
|
|
350
373
|
});
|
|
374
|
+
Object.defineProperty(exports, 'GET_GRAPHQL_ARGUMENT_CONFIG', {
|
|
375
|
+
enumerable: true,
|
|
376
|
+
get: function () {
|
|
377
|
+
return GET_GRAPHQL_ARGUMENT_CONFIG;
|
|
378
|
+
}
|
|
379
|
+
});
|
|
351
380
|
Object.defineProperty(exports, 'GET_GRAPHQL_TYPE', {
|
|
352
381
|
enumerable: true,
|
|
353
382
|
get: function () {
|