@gqloom/core 0.13.0 → 0.14.1
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/context.cjs +1 -1
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -1
- package/dist/{index-DBqGrLn7.d.cts → index-DPuy3FIT.d.cts} +178 -160
- package/dist/{index-DWjUYc0-.d.ts → index-DyGHE5li.d.ts} +178 -161
- package/dist/index.cjs +64 -25
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +64 -25
- package/dist/{parse-resolving-fields-BS_BL7I_.js → parse-resolving-fields-CH8rJgks.js} +35 -17
- package/dist/{parse-resolving-fields-BXQG_2Z-.cjs → parse-resolving-fields-Czn0O39L.cjs} +35 -17
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_parse_resolving_fields = require('./parse-resolving-fields-
|
|
1
|
+
const require_parse_resolving_fields = require('./parse-resolving-fields-Czn0O39L.cjs');
|
|
2
2
|
let graphql = require("graphql");
|
|
3
3
|
graphql = require_parse_resolving_fields.__toESM(graphql);
|
|
4
4
|
|
|
@@ -55,30 +55,13 @@ var WeaverContext = class WeaverContext {
|
|
|
55
55
|
Scalar: "Scalar"
|
|
56
56
|
};
|
|
57
57
|
aliasCounters = {};
|
|
58
|
+
aliasMap = /* @__PURE__ */ new WeakMap();
|
|
58
59
|
setAlias(namedType, alias) {
|
|
59
60
|
if (namedType.name === require_parse_resolving_fields.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
60
61
|
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (namedType.name === require_parse_resolving_fields.AUTO_ALIASING) {
|
|
65
|
-
if ((0, graphql.isObjectType)(namedType) || (0, graphql.isInputObjectType)(namedType)) {
|
|
66
|
-
this.aliasCounters["Object"] ??= 0;
|
|
67
|
-
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
68
|
-
} else if ((0, graphql.isUnionType)(namedType)) {
|
|
69
|
-
this.aliasCounters["Union"] ??= 0;
|
|
70
|
-
return namedType.name = `Union${++this.aliasCounters["Union"]}`;
|
|
71
|
-
} else if ((0, graphql.isEnumType)(namedType)) {
|
|
72
|
-
this.aliasCounters["Enum"] ??= 0;
|
|
73
|
-
return namedType.name = `Enum${++this.aliasCounters["Enum"]}`;
|
|
74
|
-
} else if ((0, graphql.isInterfaceType)(namedType)) {
|
|
75
|
-
this.aliasCounters["Interface"] ??= 0;
|
|
76
|
-
return namedType.name = `Interface${++this.aliasCounters["Interface"]}`;
|
|
77
|
-
} else if ((0, graphql.isScalarType)(namedType)) {
|
|
78
|
-
this.aliasCounters["Scalar"] ??= 0;
|
|
79
|
-
return namedType.name = `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
62
|
+
const aliases = this.ensureAliasStore(namedType);
|
|
63
|
+
if (alias) aliases.add(alias);
|
|
64
|
+
return this.pickAlias(namedType, aliases);
|
|
82
65
|
}
|
|
83
66
|
/**
|
|
84
67
|
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
@@ -92,6 +75,56 @@ var WeaverContext = class WeaverContext {
|
|
|
92
75
|
if (compareLocale !== 0) return compareLocale;
|
|
93
76
|
return 0;
|
|
94
77
|
}
|
|
78
|
+
ensureAliasStore(namedType) {
|
|
79
|
+
const existing = this.aliasMap.get(namedType);
|
|
80
|
+
if (existing) return existing;
|
|
81
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
82
|
+
this.aliasMap.set(namedType, aliases);
|
|
83
|
+
Object.defineProperty(namedType, "name", {
|
|
84
|
+
get: () => this.pickAlias(namedType, aliases),
|
|
85
|
+
set: (value) => {
|
|
86
|
+
aliases.add(value);
|
|
87
|
+
},
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true
|
|
90
|
+
});
|
|
91
|
+
return aliases;
|
|
92
|
+
}
|
|
93
|
+
pickAlias(namedType, aliases) {
|
|
94
|
+
const best = this.reduceAliases(aliases);
|
|
95
|
+
if (best && best !== require_parse_resolving_fields.AUTO_ALIASING) return best;
|
|
96
|
+
const fallback = this.createFallbackAlias(namedType);
|
|
97
|
+
aliases.add(fallback);
|
|
98
|
+
return this.reduceAliases(aliases) ?? fallback;
|
|
99
|
+
}
|
|
100
|
+
reduceAliases(aliases) {
|
|
101
|
+
let best;
|
|
102
|
+
for (const alias of aliases) if (best === void 0 || WeaverContext.higherPriorityThan(alias, best) < 0) best = alias;
|
|
103
|
+
return best;
|
|
104
|
+
}
|
|
105
|
+
createFallbackAlias(namedType) {
|
|
106
|
+
if ((0, graphql.isObjectType)(namedType) || (0, graphql.isInputObjectType)(namedType)) {
|
|
107
|
+
this.aliasCounters["Object"] ??= 0;
|
|
108
|
+
return `Object${++this.aliasCounters["Object"]}`;
|
|
109
|
+
}
|
|
110
|
+
if ((0, graphql.isUnionType)(namedType)) {
|
|
111
|
+
this.aliasCounters["Union"] ??= 0;
|
|
112
|
+
return `Union${++this.aliasCounters["Union"]}`;
|
|
113
|
+
}
|
|
114
|
+
if ((0, graphql.isEnumType)(namedType)) {
|
|
115
|
+
this.aliasCounters["Enum"] ??= 0;
|
|
116
|
+
return `Enum${++this.aliasCounters["Enum"]}`;
|
|
117
|
+
}
|
|
118
|
+
if ((0, graphql.isInterfaceType)(namedType)) {
|
|
119
|
+
this.aliasCounters["Interface"] ??= 0;
|
|
120
|
+
return `Interface${++this.aliasCounters["Interface"]}`;
|
|
121
|
+
}
|
|
122
|
+
if ((0, graphql.isScalarType)(namedType)) {
|
|
123
|
+
this.aliasCounters["Scalar"] ??= 0;
|
|
124
|
+
return `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
125
|
+
}
|
|
126
|
+
return namedType.name;
|
|
127
|
+
}
|
|
95
128
|
static provide(func, value) {
|
|
96
129
|
const lastRef = WeaverContext._ref;
|
|
97
130
|
WeaverContext._ref = value;
|
|
@@ -169,7 +202,7 @@ var GlobalWeaverContext = class {
|
|
|
169
202
|
return gqlType;
|
|
170
203
|
}
|
|
171
204
|
setAlias(namedType, alias) {
|
|
172
|
-
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
205
|
+
return WeaverContext.ref?.setAlias(namedType, alias) ?? namedType.name;
|
|
173
206
|
}
|
|
174
207
|
};
|
|
175
208
|
const weaverContext = new GlobalWeaverContext();
|
|
@@ -1581,7 +1614,10 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1581
1614
|
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
1582
1615
|
if ((0, graphql.isObjectType)(gqlType)) {
|
|
1583
1616
|
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
1584
|
-
if (gqlObject != null)
|
|
1617
|
+
if (gqlObject != null) {
|
|
1618
|
+
context.setAlias(gqlObject, getAlias());
|
|
1619
|
+
return gqlObject;
|
|
1620
|
+
}
|
|
1585
1621
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1586
1622
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1587
1623
|
context.setAlias(loomObject, getAlias());
|
|
@@ -1590,7 +1626,10 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1590
1626
|
else if ((0, graphql.isNonNullType)(gqlType)) return new graphql.GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
1591
1627
|
else if ((0, graphql.isUnionType)(gqlType)) {
|
|
1592
1628
|
const existing = context.loomUnionMap?.get(gqlType);
|
|
1593
|
-
if (existing != null)
|
|
1629
|
+
if (existing != null) {
|
|
1630
|
+
context.setAlias(existing, getAlias());
|
|
1631
|
+
return existing;
|
|
1632
|
+
}
|
|
1594
1633
|
const config = gqlType.toConfig();
|
|
1595
1634
|
const unionType = new graphql.GraphQLUnionType({
|
|
1596
1635
|
...config,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as subscription, $t as
|
|
2
|
-
export { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, types_loom_d_exports as Loom, LoomDataLoader, LoomObjectType, MayGetter, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, symbols_d_exports as SYMBOLS, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, WeaverContext, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLArgumentConfig, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
1
|
+
import { $ as subscription, $t as GraphQLSilk, A as getGraphQLType, An as FieldFactoryWithResolve, At as RequireKeys, B as ResolverFactory, Bn as StandardSchemaV1, Bt as getMemoizationMap, C as DirectiveRecord, Cn as Query, Ct as MiddlewareOptions, D as NonNullSilk, Dn as BaseChainFactory, Dt as MayGetter, E as ListSilk, En as types_loom_d_exports, Et as IsAny, F as parseSilk, Fn as QueryFactoryWithResolve, Ft as markErrorLocation, G as createQuery, Gt as getFieldOptions, H as ToExecutorProps, Ht as onlyMemoization, I as silk, In as ResolvableSubscription, It as markLocation, J as field, Jt as FieldFactory, K as createSubscription, Kt as getOperationOptions, L as ChainResolver, Ln as SubscriptionChainFactory, Lt as tryIn, M as listSilk, Mn as MutationChainFactory, Mt as BatchLoadFn, N as nonNullSilk, Nn as MutationFactoryWithResolve, Nt as EasyDataLoader, O as NullableSilk, On as ChainFactoryOptions, Ot as MayPromise, P as nullableSilk, Pn as QueryChainFactory, Pt as LoomDataLoader, Q as resolver, Qt as GraphQLFieldOptions, R as Executor, Rn as SubscriptionNeedResolve, Rt as OnlyMemoizationPayload, S as DirectiveItem, Sn as Operation, St as MiddlewareOperation, T as GQLoomExtensions, Tn as Subscription, Tt as filterMiddlewares, U as createField, Ut as AUTO_ALIASING, V as ResolverMeta, Vt as isOnlyMemoryPayload, W as createMutation, Wt as DERIVED_DEPENDENCIES, X as mutation, Xt as FieldOptions, Y as loom, Yt as FieldFactoryWithUtils, Z as query, Zt as FieldOrOperationType, _ as isSchemaVendorWeaver, _n as BaseField, _t as notNullish, a as LoomObjectType, an as OperationType, at as parseInputValue, b as ensureInputType, bn as FieldOrOperation, bt as Middleware, c as GlobalWeaverContext, cn as QueryOptions, ct as screamingSnakeCase, d as collectName, dn as ResolverOptionsWithParent, dt as getDeepResolvingFields, en as InferFieldInput, et as CallableInputParser, f as collectNames, fn as ResolverPayload, ft as getResolvingFields, g as SchemaWeaver, gn as SubscriptionOptions, gt as meta, h as weaverContext, hn as SubscriptionFactoryWithChain, ht as mapValue, i as CoreSchemaWeaverConfigOptions, in as MutationOptions, it as getStandardValue, j as isSilk, jn as IChainFactory, jt as ValueOf, k as getGraphQLArgumentConfig, kn as FieldChainFactory, kt as OmitInUnion, l as WeaverConfig, ln as ResolverOptions, lt as ResolvingFields, m as provideWeaverContext, mn as SubscriptionFactory, mt as deepMerge, n as weave, nn as MutationFactory, nt as InferInputO, o as OPERATION_OBJECT_NAMES, on as QueryFactory, ot as capitalize, p as initWeaverContext, pn as ResolvingOptions, pt as parseResolvingFields, q as defaultSubscriptionResolve, qt as getSubscriptionOptions, r as CoreSchemaWeaverConfig, rn as MutationFactoryWithChain, rt as createInputParser, s as getCacheType, sn as QueryFactoryWithChain, st as pascalCase, t as GraphQLSchemaLoom, tn as InferFieldOutput, tt as InferInputI, u as WeaverContext, un as ResolverOptionsWithExtensions, ut as ResolvingFieldsOptions, v as ensureInterfaceType, vn as Field, vt as toObjMap, w as GQLoomExtensionAttribute, wn as Resolver, wt as applyMiddlewares, x as inputToArgs, xn as Mutation, xt as MiddlewareConfig, y as ensureInputObjectType, yn as FieldMeta, yt as CallableMiddlewareOptions, z as ObjectChainResolver, zn as symbols_d_exports, zt as assignContextMap } from "./index-DPuy3FIT.cjs";
|
|
2
|
+
export { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, types_loom_d_exports as Loom, LoomDataLoader, LoomObjectType, MayGetter, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingFieldsOptions, ResolvingOptions, symbols_d_exports as SYMBOLS, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, WeaverContext, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLArgumentConfig, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as subscription, $t as
|
|
2
|
-
export { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, types_loom_d_exports as Loom, LoomDataLoader, LoomObjectType, MayGetter, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, symbols_d_exports as SYMBOLS, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, WeaverContext, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLArgumentConfig, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
1
|
+
import { $ as subscription, $t as GraphQLSilk, A as getGraphQLType, An as FieldFactoryWithResolve, At as RequireKeys, B as ResolverFactory, Bn as StandardSchemaV1, Bt as getMemoizationMap, C as DirectiveRecord, Cn as Query, Ct as MiddlewareOptions, D as NonNullSilk, Dn as BaseChainFactory, Dt as MayGetter, E as ListSilk, En as types_loom_d_exports, Et as IsAny, F as parseSilk, Fn as QueryFactoryWithResolve, Ft as markErrorLocation, G as createQuery, Gt as getFieldOptions, H as ToExecutorProps, Ht as onlyMemoization, I as silk, In as ResolvableSubscription, It as markLocation, J as field, Jt as FieldFactory, K as createSubscription, Kt as getOperationOptions, L as ChainResolver, Ln as SubscriptionChainFactory, Lt as tryIn, M as listSilk, Mn as MutationChainFactory, Mt as BatchLoadFn, N as nonNullSilk, Nn as MutationFactoryWithResolve, Nt as EasyDataLoader, O as NullableSilk, On as ChainFactoryOptions, Ot as MayPromise, P as nullableSilk, Pn as QueryChainFactory, Pt as LoomDataLoader, Q as resolver, Qt as GraphQLFieldOptions, R as Executor, Rn as SubscriptionNeedResolve, Rt as OnlyMemoizationPayload, S as DirectiveItem, Sn as Operation, St as MiddlewareOperation, T as GQLoomExtensions, Tn as Subscription, Tt as filterMiddlewares, U as createField, Ut as AUTO_ALIASING, V as ResolverMeta, Vt as isOnlyMemoryPayload, W as createMutation, Wt as DERIVED_DEPENDENCIES, X as mutation, Xt as FieldOptions, Y as loom, Yt as FieldFactoryWithUtils, Z as query, Zt as FieldOrOperationType, _ as isSchemaVendorWeaver, _n as BaseField, _t as notNullish, a as LoomObjectType, an as OperationType, at as parseInputValue, b as ensureInputType, bn as FieldOrOperation, bt as Middleware, c as GlobalWeaverContext, cn as QueryOptions, ct as screamingSnakeCase, d as collectName, dn as ResolverOptionsWithParent, dt as getDeepResolvingFields, en as InferFieldInput, et as CallableInputParser, f as collectNames, fn as ResolverPayload, ft as getResolvingFields, g as SchemaWeaver, gn as SubscriptionOptions, gt as meta, h as weaverContext, hn as SubscriptionFactoryWithChain, ht as mapValue, i as CoreSchemaWeaverConfigOptions, in as MutationOptions, it as getStandardValue, j as isSilk, jn as IChainFactory, jt as ValueOf, k as getGraphQLArgumentConfig, kn as FieldChainFactory, kt as OmitInUnion, l as WeaverConfig, ln as ResolverOptions, lt as ResolvingFields, m as provideWeaverContext, mn as SubscriptionFactory, mt as deepMerge, n as weave, nn as MutationFactory, nt as InferInputO, o as OPERATION_OBJECT_NAMES, on as QueryFactory, ot as capitalize, p as initWeaverContext, pn as ResolvingOptions, pt as parseResolvingFields, q as defaultSubscriptionResolve, qt as getSubscriptionOptions, r as CoreSchemaWeaverConfig, rn as MutationFactoryWithChain, rt as createInputParser, s as getCacheType, sn as QueryFactoryWithChain, st as pascalCase, t as GraphQLSchemaLoom, tn as InferFieldOutput, tt as InferInputI, u as WeaverContext, un as ResolverOptionsWithExtensions, ut as ResolvingFieldsOptions, v as ensureInterfaceType, vn as Field, vt as toObjMap, w as GQLoomExtensionAttribute, wn as Resolver, wt as applyMiddlewares, x as inputToArgs, xn as Mutation, xt as MiddlewareConfig, y as ensureInputObjectType, yn as FieldMeta, yt as CallableMiddlewareOptions, z as ObjectChainResolver, zn as symbols_d_exports, zt as assignContextMap } from "./index-DyGHE5li.js";
|
|
2
|
+
export { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, types_loom_d_exports as Loom, LoomDataLoader, LoomObjectType, MayGetter, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingFieldsOptions, ResolvingOptions, symbols_d_exports as SYMBOLS, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, WeaverContext, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLArgumentConfig, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getMemoizationMap, c as FIELD_HIDDEN, d as IS_RESOLVER, f as WEAVER_CONFIG, h as DERIVED_DEPENDENCIES, i as assignContextMap, l as GET_GRAPHQL_ARGUMENT_CONFIG, m as AUTO_ALIASING, n as getResolvingFields, o as isOnlyMemoryPayload, p as symbols_exports, r as parseResolvingFields, s as onlyMemoization, t as getDeepResolvingFields, u as GET_GRAPHQL_TYPE } from "./parse-resolving-fields-
|
|
1
|
+
import { a as getMemoizationMap, c as FIELD_HIDDEN, d as IS_RESOLVER, f as WEAVER_CONFIG, h as DERIVED_DEPENDENCIES, i as assignContextMap, l as GET_GRAPHQL_ARGUMENT_CONFIG, m as AUTO_ALIASING, n as getResolvingFields, o as isOnlyMemoryPayload, p as symbols_exports, r as parseResolvingFields, s as onlyMemoization, t as getDeepResolvingFields, u as GET_GRAPHQL_TYPE } from "./parse-resolving-fields-CH8rJgks.js";
|
|
2
2
|
import { GraphQLError, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, assertName, isEnumType, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, resolveObjMapThunk } from "graphql";
|
|
3
3
|
|
|
4
4
|
//#region src/schema/weaver-context.ts
|
|
@@ -54,30 +54,13 @@ var WeaverContext = class WeaverContext {
|
|
|
54
54
|
Scalar: "Scalar"
|
|
55
55
|
};
|
|
56
56
|
aliasCounters = {};
|
|
57
|
+
aliasMap = /* @__PURE__ */ new WeakMap();
|
|
57
58
|
setAlias(namedType, alias) {
|
|
58
59
|
if (namedType.name === AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
59
60
|
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (namedType.name === AUTO_ALIASING) {
|
|
64
|
-
if (isObjectType(namedType) || isInputObjectType(namedType)) {
|
|
65
|
-
this.aliasCounters["Object"] ??= 0;
|
|
66
|
-
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
67
|
-
} else if (isUnionType(namedType)) {
|
|
68
|
-
this.aliasCounters["Union"] ??= 0;
|
|
69
|
-
return namedType.name = `Union${++this.aliasCounters["Union"]}`;
|
|
70
|
-
} else if (isEnumType(namedType)) {
|
|
71
|
-
this.aliasCounters["Enum"] ??= 0;
|
|
72
|
-
return namedType.name = `Enum${++this.aliasCounters["Enum"]}`;
|
|
73
|
-
} else if (isInterfaceType(namedType)) {
|
|
74
|
-
this.aliasCounters["Interface"] ??= 0;
|
|
75
|
-
return namedType.name = `Interface${++this.aliasCounters["Interface"]}`;
|
|
76
|
-
} else if (isScalarType(namedType)) {
|
|
77
|
-
this.aliasCounters["Scalar"] ??= 0;
|
|
78
|
-
return namedType.name = `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
61
|
+
const aliases = this.ensureAliasStore(namedType);
|
|
62
|
+
if (alias) aliases.add(alias);
|
|
63
|
+
return this.pickAlias(namedType, aliases);
|
|
81
64
|
}
|
|
82
65
|
/**
|
|
83
66
|
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
@@ -91,6 +74,56 @@ var WeaverContext = class WeaverContext {
|
|
|
91
74
|
if (compareLocale !== 0) return compareLocale;
|
|
92
75
|
return 0;
|
|
93
76
|
}
|
|
77
|
+
ensureAliasStore(namedType) {
|
|
78
|
+
const existing = this.aliasMap.get(namedType);
|
|
79
|
+
if (existing) return existing;
|
|
80
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
81
|
+
this.aliasMap.set(namedType, aliases);
|
|
82
|
+
Object.defineProperty(namedType, "name", {
|
|
83
|
+
get: () => this.pickAlias(namedType, aliases),
|
|
84
|
+
set: (value) => {
|
|
85
|
+
aliases.add(value);
|
|
86
|
+
},
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true
|
|
89
|
+
});
|
|
90
|
+
return aliases;
|
|
91
|
+
}
|
|
92
|
+
pickAlias(namedType, aliases) {
|
|
93
|
+
const best = this.reduceAliases(aliases);
|
|
94
|
+
if (best && best !== AUTO_ALIASING) return best;
|
|
95
|
+
const fallback = this.createFallbackAlias(namedType);
|
|
96
|
+
aliases.add(fallback);
|
|
97
|
+
return this.reduceAliases(aliases) ?? fallback;
|
|
98
|
+
}
|
|
99
|
+
reduceAliases(aliases) {
|
|
100
|
+
let best;
|
|
101
|
+
for (const alias of aliases) if (best === void 0 || WeaverContext.higherPriorityThan(alias, best) < 0) best = alias;
|
|
102
|
+
return best;
|
|
103
|
+
}
|
|
104
|
+
createFallbackAlias(namedType) {
|
|
105
|
+
if (isObjectType(namedType) || isInputObjectType(namedType)) {
|
|
106
|
+
this.aliasCounters["Object"] ??= 0;
|
|
107
|
+
return `Object${++this.aliasCounters["Object"]}`;
|
|
108
|
+
}
|
|
109
|
+
if (isUnionType(namedType)) {
|
|
110
|
+
this.aliasCounters["Union"] ??= 0;
|
|
111
|
+
return `Union${++this.aliasCounters["Union"]}`;
|
|
112
|
+
}
|
|
113
|
+
if (isEnumType(namedType)) {
|
|
114
|
+
this.aliasCounters["Enum"] ??= 0;
|
|
115
|
+
return `Enum${++this.aliasCounters["Enum"]}`;
|
|
116
|
+
}
|
|
117
|
+
if (isInterfaceType(namedType)) {
|
|
118
|
+
this.aliasCounters["Interface"] ??= 0;
|
|
119
|
+
return `Interface${++this.aliasCounters["Interface"]}`;
|
|
120
|
+
}
|
|
121
|
+
if (isScalarType(namedType)) {
|
|
122
|
+
this.aliasCounters["Scalar"] ??= 0;
|
|
123
|
+
return `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
124
|
+
}
|
|
125
|
+
return namedType.name;
|
|
126
|
+
}
|
|
94
127
|
static provide(func, value) {
|
|
95
128
|
const lastRef = WeaverContext._ref;
|
|
96
129
|
WeaverContext._ref = value;
|
|
@@ -168,7 +201,7 @@ var GlobalWeaverContext = class {
|
|
|
168
201
|
return gqlType;
|
|
169
202
|
}
|
|
170
203
|
setAlias(namedType, alias) {
|
|
171
|
-
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
204
|
+
return WeaverContext.ref?.setAlias(namedType, alias) ?? namedType.name;
|
|
172
205
|
}
|
|
173
206
|
};
|
|
174
207
|
const weaverContext = new GlobalWeaverContext();
|
|
@@ -1580,7 +1613,10 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1580
1613
|
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
1581
1614
|
if (isObjectType(gqlType)) {
|
|
1582
1615
|
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
1583
|
-
if (gqlObject != null)
|
|
1616
|
+
if (gqlObject != null) {
|
|
1617
|
+
context.setAlias(gqlObject, getAlias());
|
|
1618
|
+
return gqlObject;
|
|
1619
|
+
}
|
|
1584
1620
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1585
1621
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1586
1622
|
context.setAlias(loomObject, getAlias());
|
|
@@ -1589,7 +1625,10 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1589
1625
|
else if (isNonNullType(gqlType)) return new GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
1590
1626
|
else if (isUnionType(gqlType)) {
|
|
1591
1627
|
const existing = context.loomUnionMap?.get(gqlType);
|
|
1592
|
-
if (existing != null)
|
|
1628
|
+
if (existing != null) {
|
|
1629
|
+
context.setAlias(existing, getAlias());
|
|
1630
|
+
return existing;
|
|
1631
|
+
}
|
|
1593
1632
|
const config = gqlType.toConfig();
|
|
1594
1633
|
const unionType = new GraphQLUnionType({
|
|
1595
1634
|
...config,
|
|
@@ -84,12 +84,17 @@ function unwrapType(gqlType) {
|
|
|
84
84
|
* Analyzes and processes field resolution in a GraphQL query deeply.
|
|
85
85
|
*
|
|
86
86
|
* @param payload - The resolver payload containing the current field resolution context
|
|
87
|
-
* @param
|
|
87
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = Infinity)
|
|
88
88
|
* @returns A map of field paths to their resolving fields
|
|
89
89
|
*/
|
|
90
|
-
function getDeepResolvingFields(payload,
|
|
90
|
+
function getDeepResolvingFields(payload, options) {
|
|
91
|
+
const resolvedDepth = options?.maxDepth ?? Infinity;
|
|
92
|
+
const mergedOptions = {
|
|
93
|
+
...options,
|
|
94
|
+
maxDepth: resolvedDepth
|
|
95
|
+
};
|
|
91
96
|
const result = /* @__PURE__ */ new Map();
|
|
92
|
-
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info,
|
|
97
|
+
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info, mergedOptions);
|
|
93
98
|
const rootType = unwrapType(payload.info.returnType);
|
|
94
99
|
for (const [path, requestedFields] of requestedFieldsByPath.entries()) {
|
|
95
100
|
let currentType = rootType;
|
|
@@ -145,10 +150,14 @@ function getDeepResolvingFields(payload, maxDepth = Infinity) {
|
|
|
145
150
|
* Analyzes and processes field resolution in a GraphQL query.
|
|
146
151
|
*
|
|
147
152
|
* @param payload - The resolver payload containing the current field resolution context
|
|
153
|
+
* @param options - Additional parsing options (e.g., includeIntrospection; fixed maxDepth = 1)
|
|
148
154
|
* @returns An object containing sets of different field types
|
|
149
155
|
*/
|
|
150
|
-
function getResolvingFields(payload) {
|
|
151
|
-
const requestedFields = parseResolvingFields(payload.info
|
|
156
|
+
function getResolvingFields(payload, options) {
|
|
157
|
+
const requestedFields = parseResolvingFields(payload.info, {
|
|
158
|
+
...options,
|
|
159
|
+
maxDepth: 1
|
|
160
|
+
});
|
|
152
161
|
const derivedFields = /* @__PURE__ */ new Set();
|
|
153
162
|
const derivedDependencies = /* @__PURE__ */ new Set();
|
|
154
163
|
const resolvingObject = unwrapType(payload.info.returnType);
|
|
@@ -181,11 +190,16 @@ function getResolvingFields(payload) {
|
|
|
181
190
|
* Supports @include, @skip directives, fragments, and variables.
|
|
182
191
|
*
|
|
183
192
|
* @param info - The GraphQL resolve info object containing the query information
|
|
184
|
-
* @param
|
|
193
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = 1)
|
|
185
194
|
* @returns A Set of field paths
|
|
186
195
|
*/
|
|
187
|
-
function parseResolvingFields(info,
|
|
188
|
-
|
|
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);
|
|
189
203
|
}
|
|
190
204
|
/**
|
|
191
205
|
* Class responsible for parsing GraphQL resolve info to extract all requested fields.
|
|
@@ -197,17 +211,20 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
197
211
|
visitedFragments = /* @__PURE__ */ new Set();
|
|
198
212
|
/** The GraphQL resolve info object */
|
|
199
213
|
info;
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
-
static parse(info,
|
|
203
|
-
return new ResolvingFieldsParser(info,
|
|
214
|
+
/** Options controlling parsing behavior */
|
|
215
|
+
options;
|
|
216
|
+
static parse(info, options) {
|
|
217
|
+
return new ResolvingFieldsParser(info, options).parse();
|
|
204
218
|
}
|
|
205
|
-
static parseDeep(info,
|
|
206
|
-
return new ResolvingFieldsParser(info,
|
|
219
|
+
static parseDeep(info, options) {
|
|
220
|
+
return new ResolvingFieldsParser(info, options).parseDeep();
|
|
207
221
|
}
|
|
208
|
-
constructor(info,
|
|
222
|
+
constructor(info, options) {
|
|
209
223
|
this.info = info;
|
|
210
|
-
this.
|
|
224
|
+
this.options = {
|
|
225
|
+
maxDepth: options?.maxDepth ?? Infinity,
|
|
226
|
+
includeIntrospection: options?.includeIntrospection ?? false
|
|
227
|
+
};
|
|
211
228
|
for (const fieldNode of this.info.fieldNodes) this.collectFields(fieldNode.selectionSet, "", 0);
|
|
212
229
|
}
|
|
213
230
|
/**
|
|
@@ -239,7 +256,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
239
256
|
* @param currentDepth - Current depth of recursion
|
|
240
257
|
*/
|
|
241
258
|
collectFields(selectionSet, parentPath = "", currentDepth = 0) {
|
|
242
|
-
if (!selectionSet?.selections.length || currentDepth >= this.maxDepth) return;
|
|
259
|
+
if (!selectionSet?.selections.length || currentDepth >= this.options.maxDepth) return;
|
|
243
260
|
if (!this.fields.has(parentPath)) this.fields.set(parentPath, /* @__PURE__ */ new Set());
|
|
244
261
|
const currentFields = this.fields.get(parentPath);
|
|
245
262
|
for (const selection of selectionSet.selections) {
|
|
@@ -247,6 +264,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
247
264
|
switch (selection.kind) {
|
|
248
265
|
case Kind.FIELD: {
|
|
249
266
|
const fieldName = selection.name.value;
|
|
267
|
+
if (!this.options.includeIntrospection && fieldName.startsWith("__")) break;
|
|
250
268
|
currentFields.add(fieldName);
|
|
251
269
|
if (selection.selectionSet != null) {
|
|
252
270
|
const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
|
|
@@ -115,12 +115,17 @@ function unwrapType(gqlType) {
|
|
|
115
115
|
* Analyzes and processes field resolution in a GraphQL query deeply.
|
|
116
116
|
*
|
|
117
117
|
* @param payload - The resolver payload containing the current field resolution context
|
|
118
|
-
* @param
|
|
118
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = Infinity)
|
|
119
119
|
* @returns A map of field paths to their resolving fields
|
|
120
120
|
*/
|
|
121
|
-
function getDeepResolvingFields(payload,
|
|
121
|
+
function getDeepResolvingFields(payload, options) {
|
|
122
|
+
const resolvedDepth = options?.maxDepth ?? Infinity;
|
|
123
|
+
const mergedOptions = {
|
|
124
|
+
...options,
|
|
125
|
+
maxDepth: resolvedDepth
|
|
126
|
+
};
|
|
122
127
|
const result = /* @__PURE__ */ new Map();
|
|
123
|
-
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info,
|
|
128
|
+
const requestedFieldsByPath = ResolvingFieldsParser.parseDeep(payload.info, mergedOptions);
|
|
124
129
|
const rootType = unwrapType(payload.info.returnType);
|
|
125
130
|
for (const [path, requestedFields] of requestedFieldsByPath.entries()) {
|
|
126
131
|
let currentType = rootType;
|
|
@@ -176,10 +181,14 @@ function getDeepResolvingFields(payload, maxDepth = Infinity) {
|
|
|
176
181
|
* Analyzes and processes field resolution in a GraphQL query.
|
|
177
182
|
*
|
|
178
183
|
* @param payload - The resolver payload containing the current field resolution context
|
|
184
|
+
* @param options - Additional parsing options (e.g., includeIntrospection; fixed maxDepth = 1)
|
|
179
185
|
* @returns An object containing sets of different field types
|
|
180
186
|
*/
|
|
181
|
-
function getResolvingFields(payload) {
|
|
182
|
-
const requestedFields = parseResolvingFields(payload.info
|
|
187
|
+
function getResolvingFields(payload, options) {
|
|
188
|
+
const requestedFields = parseResolvingFields(payload.info, {
|
|
189
|
+
...options,
|
|
190
|
+
maxDepth: 1
|
|
191
|
+
});
|
|
183
192
|
const derivedFields = /* @__PURE__ */ new Set();
|
|
184
193
|
const derivedDependencies = /* @__PURE__ */ new Set();
|
|
185
194
|
const resolvingObject = unwrapType(payload.info.returnType);
|
|
@@ -212,11 +221,16 @@ function getResolvingFields(payload) {
|
|
|
212
221
|
* Supports @include, @skip directives, fragments, and variables.
|
|
213
222
|
*
|
|
214
223
|
* @param info - The GraphQL resolve info object containing the query information
|
|
215
|
-
* @param
|
|
224
|
+
* @param options - Additional parsing options (e.g., includeIntrospection, maxDepth; default maxDepth = 1)
|
|
216
225
|
* @returns A Set of field paths
|
|
217
226
|
*/
|
|
218
|
-
function parseResolvingFields(info,
|
|
219
|
-
|
|
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);
|
|
220
234
|
}
|
|
221
235
|
/**
|
|
222
236
|
* Class responsible for parsing GraphQL resolve info to extract all requested fields.
|
|
@@ -228,17 +242,20 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
228
242
|
visitedFragments = /* @__PURE__ */ new Set();
|
|
229
243
|
/** The GraphQL resolve info object */
|
|
230
244
|
info;
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
static parse(info,
|
|
234
|
-
return new ResolvingFieldsParser(info,
|
|
245
|
+
/** Options controlling parsing behavior */
|
|
246
|
+
options;
|
|
247
|
+
static parse(info, options) {
|
|
248
|
+
return new ResolvingFieldsParser(info, options).parse();
|
|
235
249
|
}
|
|
236
|
-
static parseDeep(info,
|
|
237
|
-
return new ResolvingFieldsParser(info,
|
|
250
|
+
static parseDeep(info, options) {
|
|
251
|
+
return new ResolvingFieldsParser(info, options).parseDeep();
|
|
238
252
|
}
|
|
239
|
-
constructor(info,
|
|
253
|
+
constructor(info, options) {
|
|
240
254
|
this.info = info;
|
|
241
|
-
this.
|
|
255
|
+
this.options = {
|
|
256
|
+
maxDepth: options?.maxDepth ?? Infinity,
|
|
257
|
+
includeIntrospection: options?.includeIntrospection ?? false
|
|
258
|
+
};
|
|
242
259
|
for (const fieldNode of this.info.fieldNodes) this.collectFields(fieldNode.selectionSet, "", 0);
|
|
243
260
|
}
|
|
244
261
|
/**
|
|
@@ -270,7 +287,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
270
287
|
* @param currentDepth - Current depth of recursion
|
|
271
288
|
*/
|
|
272
289
|
collectFields(selectionSet, parentPath = "", currentDepth = 0) {
|
|
273
|
-
if (!selectionSet?.selections.length || currentDepth >= this.maxDepth) return;
|
|
290
|
+
if (!selectionSet?.selections.length || currentDepth >= this.options.maxDepth) return;
|
|
274
291
|
if (!this.fields.has(parentPath)) this.fields.set(parentPath, /* @__PURE__ */ new Set());
|
|
275
292
|
const currentFields = this.fields.get(parentPath);
|
|
276
293
|
for (const selection of selectionSet.selections) {
|
|
@@ -278,6 +295,7 @@ var ResolvingFieldsParser = class ResolvingFieldsParser {
|
|
|
278
295
|
switch (selection.kind) {
|
|
279
296
|
case graphql.Kind.FIELD: {
|
|
280
297
|
const fieldName = selection.name.value;
|
|
298
|
+
if (!this.options.includeIntrospection && fieldName.startsWith("__")) break;
|
|
281
299
|
currentFields.add(fieldName);
|
|
282
300
|
if (selection.selectionSet != null) {
|
|
283
301
|
const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
|