@m1212e/rumble 0.23.13 → 0.23.14
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/out/index.cjs +40 -38
- package/out/index.cjs.map +1 -1
- package/out/index.mjs +39 -38
- package/out/index.mjs.map +1 -1
- package/package.json +2 -1
package/out/index.cjs
CHANGED
|
@@ -46,6 +46,8 @@ _pothos_plugin_smart_subscriptions = __toESM(_pothos_plugin_smart_subscriptions,
|
|
|
46
46
|
let _pothos_plugin_tracing = require("@pothos/plugin-tracing");
|
|
47
47
|
_pothos_plugin_tracing = __toESM(_pothos_plugin_tracing, 1);
|
|
48
48
|
let graphql_scalars = require("graphql-scalars");
|
|
49
|
+
let dataloader = require("dataloader");
|
|
50
|
+
dataloader = __toESM(dataloader, 1);
|
|
49
51
|
//#region lib/types/rumbleError.ts
|
|
50
52
|
/**
|
|
51
53
|
* An error that gets raised by rumble whenever something does not go according to plan.
|
|
@@ -208,7 +210,7 @@ function mapNullFieldsToUndefined(obj) {
|
|
|
208
210
|
}
|
|
209
211
|
//#endregion
|
|
210
212
|
//#region package.json
|
|
211
|
-
var version = "0.23.
|
|
213
|
+
var version = "0.23.14";
|
|
212
214
|
//#endregion
|
|
213
215
|
//#region lib/helpers/mergeFilters.ts
|
|
214
216
|
const EmptyFilter$1 = Symbol.for("drizzle:EmptyFilter");
|
|
@@ -2309,6 +2311,30 @@ var RuntimeFiltersPlugin = class extends _pothos_core.BasePlugin {
|
|
|
2309
2311
|
tracer;
|
|
2310
2312
|
tracerEnabled;
|
|
2311
2313
|
logger;
|
|
2314
|
+
filterLoaders = /* @__PURE__ */ new WeakMap();
|
|
2315
|
+
getLoader(context, filter) {
|
|
2316
|
+
let perContext = this.filterLoaders.get(context);
|
|
2317
|
+
if (!perContext) {
|
|
2318
|
+
perContext = /* @__PURE__ */ new Map();
|
|
2319
|
+
this.filterLoaders.set(context, perContext);
|
|
2320
|
+
}
|
|
2321
|
+
let loader = perContext.get(filter);
|
|
2322
|
+
if (!loader) {
|
|
2323
|
+
const prefetchPromise = filter.prefetch ? filter.prefetch({ context }) : void 0;
|
|
2324
|
+
loader = new dataloader.default(async (entities) => {
|
|
2325
|
+
const prefetched = prefetchPromise ? await prefetchPromise : void 0;
|
|
2326
|
+
const allowed = await filter.filter({
|
|
2327
|
+
context,
|
|
2328
|
+
entities,
|
|
2329
|
+
prefetched
|
|
2330
|
+
});
|
|
2331
|
+
const allowedSet = new Set(allowed);
|
|
2332
|
+
return entities.map((entity) => allowedSet.has(entity) ? entity : null);
|
|
2333
|
+
}, { cache: false });
|
|
2334
|
+
perContext.set(filter, loader);
|
|
2335
|
+
}
|
|
2336
|
+
return loader;
|
|
2337
|
+
}
|
|
2312
2338
|
onTypeConfig(typeConfig) {
|
|
2313
2339
|
this.tracer = this.builder.options.otel?.tracer;
|
|
2314
2340
|
this.tracerEnabled = this.builder.options.otel?.enabled;
|
|
@@ -2325,44 +2351,20 @@ var RuntimeFiltersPlugin = class extends _pothos_core.BasePlugin {
|
|
|
2325
2351
|
const runFilters = async (span) => {
|
|
2326
2352
|
const allFilters = Array.isArray(filters) ? filters : [filters];
|
|
2327
2353
|
span?.setAttribute("filters.total", allFilters.length);
|
|
2328
|
-
const
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2354
|
+
const loaders = allFilters.map((filter) => this.getLoader(context, filter));
|
|
2355
|
+
let resolved;
|
|
2356
|
+
if (this.tracer && this.tracerEnabled) resolved = await this.tracer.startActiveSpan(`rumble.filter.resolve`, async (span) => {
|
|
2357
|
+
span.setAttribute("graphql.field.name", fieldConfig.name);
|
|
2358
|
+
try {
|
|
2359
|
+
return await resolver(parent, args, context, info);
|
|
2360
|
+
} finally {
|
|
2361
|
+
span.end();
|
|
2336
2362
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
let resolved, prefetchedFilters;
|
|
2343
|
-
if (this.tracer && this.tracerEnabled) {
|
|
2344
|
-
const o = await this.tracer.startActiveSpan(`rumble.filter.resolve`, async (span) => {
|
|
2345
|
-
span.setAttribute("graphql.field.name", fieldConfig.name);
|
|
2346
|
-
try {
|
|
2347
|
-
return await Promise.all([resolver(parent, args, context, info), prefetchedFiltersPromises]);
|
|
2348
|
-
} finally {
|
|
2349
|
-
span.end();
|
|
2350
|
-
}
|
|
2351
|
-
});
|
|
2352
|
-
resolved = o[0];
|
|
2353
|
-
prefetchedFilters = o[1];
|
|
2354
|
-
} else {
|
|
2355
|
-
const o = await Promise.all([resolver(parent, args, context, info), prefetchedFiltersPromises]);
|
|
2356
|
-
resolved = o[0];
|
|
2357
|
-
prefetchedFilters = o[1];
|
|
2358
|
-
}
|
|
2359
|
-
const allowed = Array.from((await Promise.all(prefetchedFilters.map((f) => f({
|
|
2360
|
-
context,
|
|
2361
|
-
entities: Array.isArray(resolved) ? resolved : [resolved]
|
|
2362
|
-
})))).reduce((acc, val) => {
|
|
2363
|
-
for (const element of val) acc.add(element);
|
|
2364
|
-
return acc;
|
|
2365
|
-
}, /* @__PURE__ */ new Set()));
|
|
2363
|
+
});
|
|
2364
|
+
else resolved = await resolver(parent, args, context, info);
|
|
2365
|
+
const entities = Array.isArray(resolved) ? resolved : [resolved];
|
|
2366
|
+
const perFilterResults = await Promise.all(loaders.map((loader) => Promise.all(entities.map((entity) => loader.load(entity)))));
|
|
2367
|
+
const allowed = entities.filter((_, index) => perFilterResults.some((results) => results[index] != null));
|
|
2366
2368
|
span?.setAttribute("filters.allowed", allowed.length);
|
|
2367
2369
|
this.logger?.debug({
|
|
2368
2370
|
"graphql.field.name": fieldConfig.name,
|