grafast 0.1.1-beta.10 → 0.1.1-beta.11
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/args.d.ts +4 -7
- package/dist/args.js +47 -37
- package/dist/config.d.ts +0 -17
- package/dist/config.js +1 -95
- package/dist/dev.js +2 -4
- package/dist/engine/executeBucket.js +24 -5
- package/dist/execute.d.ts +2 -2
- package/dist/execute.js +27 -6
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +33 -13
- package/dist/index.d.ts +21 -12
- package/dist/index.js +5 -2
- package/dist/interfaces.d.ts +45 -2
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +25 -0
- package/dist/prepare.js +23 -5
- package/dist/subscribe.js +23 -3
- package/dist/utils.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/args.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { ExecutionArgs } from "graphql";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
export declare function hookArgs(rawArgs: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset, ctx: Partial<Grafast.RequestContext>): Grafast.ExecutionArgs | PromiseLike<Grafast.ExecutionArgs>;
|
|
2
|
+
import type { GrafastExecutionArgs, PromiseOrDirect } from "./interfaces.js";
|
|
3
|
+
/** @deprecated Pass `resolvedPreset` and `requestContext` via args directly */
|
|
4
|
+
export declare function hookArgs(rawArgs: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset, ctx: Partial<Grafast.RequestContext>): PromiseOrDirect<Grafast.ExecutionArgs>;
|
|
5
|
+
export declare function hookArgs(rawArgs: GrafastExecutionArgs): PromiseOrDirect<Grafast.ExecutionArgs>;
|
|
9
6
|
//# sourceMappingURL=args.d.ts.map
|
package/dist/args.js
CHANGED
|
@@ -1,62 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hookArgs = void 0;
|
|
4
|
-
const config_js_1 = require("./config.js");
|
|
5
4
|
const interfaces_js_1 = require("./interfaces.js");
|
|
5
|
+
const middleware_js_1 = require("./middleware.js");
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
|
+
const EMPTY_OBJECT = Object.freeze(Object.create(null));
|
|
7
8
|
/**
|
|
8
9
|
* Applies Graphile Config hooks to your GraphQL request, e.g. to
|
|
9
10
|
* populate context or similar.
|
|
10
11
|
*
|
|
11
12
|
* @experimental
|
|
12
13
|
*/
|
|
13
|
-
function hookArgs(rawArgs,
|
|
14
|
+
function hookArgs(rawArgs, legacyResolvedPreset, legacyCtx) {
|
|
15
|
+
if (legacyResolvedPreset !== undefined) {
|
|
16
|
+
rawArgs.resolvedPreset = legacyResolvedPreset;
|
|
17
|
+
}
|
|
18
|
+
if (legacyCtx !== undefined) {
|
|
19
|
+
rawArgs.requestContext = rawArgs.requestContext ?? legacyCtx;
|
|
20
|
+
}
|
|
21
|
+
const { middleware: rawMiddleware, resolvedPreset, contextValue: rawContextValue, } = rawArgs;
|
|
22
|
+
// Make context mutable
|
|
23
|
+
rawArgs.contextValue = Object.assign(Object.create(null), rawContextValue);
|
|
24
|
+
const middleware = rawMiddleware === undefined && resolvedPreset != null
|
|
25
|
+
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
|
|
26
|
+
: rawMiddleware ?? null;
|
|
27
|
+
if (rawMiddleware === undefined) {
|
|
28
|
+
rawArgs.middleware = middleware;
|
|
29
|
+
}
|
|
14
30
|
const args = rawArgs;
|
|
15
31
|
// Assert that args haven't already been hooked
|
|
16
32
|
if (args[interfaces_js_1.$$hooked]) {
|
|
17
33
|
throw new Error("Must not call hookArgs twice!");
|
|
18
34
|
}
|
|
19
35
|
args[interfaces_js_1.$$hooked] = true;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (middleware != null) {
|
|
37
|
+
return middleware.run("prepareArgs", { args }, finalizeWithEvent);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return finalize(args);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.hookArgs = hookArgs;
|
|
44
|
+
function finalize(args) {
|
|
45
|
+
const userContext = args.resolvedPreset?.grafast?.context;
|
|
46
|
+
const contextValue = args.contextValue;
|
|
47
|
+
if (typeof userContext === "function") {
|
|
48
|
+
const result = userContext(args.requestContext ?? EMPTY_OBJECT, args);
|
|
49
|
+
if ((0, utils_js_1.isPromiseLike)(result)) {
|
|
50
|
+
// Deliberately shadowed 'result'
|
|
51
|
+
return result.then((result) => {
|
|
52
|
+
Object.assign(contextValue, result);
|
|
36
53
|
return args;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (typeof userContext === "object" && userContext !== null) {
|
|
40
|
-
Object.assign(args.contextValue, userContext);
|
|
41
|
-
return args;
|
|
54
|
+
});
|
|
42
55
|
}
|
|
43
56
|
else {
|
|
57
|
+
Object.assign(contextValue, result);
|
|
44
58
|
return args;
|
|
45
59
|
}
|
|
46
|
-
};
|
|
47
|
-
if (resolvedPreset !== config_js_1.NULL_PRESET &&
|
|
48
|
-
resolvedPreset.plugins &&
|
|
49
|
-
resolvedPreset.plugins.length > 0) {
|
|
50
|
-
const event = { args, ctx, resolvedPreset };
|
|
51
|
-
const result = (0, config_js_1.hook)(resolvedPreset, "args", event);
|
|
52
|
-
if ((0, utils_js_1.isPromiseLike)(result)) {
|
|
53
|
-
return result.then(() => finalize(event.args));
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return finalize(event.args);
|
|
57
|
-
}
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
else if (typeof userContext === "object" && userContext !== null) {
|
|
62
|
+
Object.assign(contextValue, userContext);
|
|
63
|
+
return args;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return args;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function finalizeWithEvent(event) {
|
|
70
|
+
return finalize(event.args);
|
|
60
71
|
}
|
|
61
|
-
exports.hookArgs = hookArgs;
|
|
62
72
|
//# sourceMappingURL=args.js.map
|
package/dist/config.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
import type { AsyncHooks, PluginHook } from "graphile-config";
|
|
2
1
|
export declare const NULL_PRESET: GraphileConfig.ResolvedPreset;
|
|
3
|
-
type GraphileConfigModule = typeof import("graphile-config");
|
|
4
|
-
type PromiseOrValue<T> = T | Promise<T>;
|
|
5
|
-
export declare function withGraphileConfig<T>(callback: (graphileConfig: GraphileConfigModule | null) => PromiseOrValue<T>): PromiseOrValue<T>;
|
|
6
|
-
declare const $$skipHooks: unique symbol;
|
|
7
|
-
declare const $$hooksForPreset: unique symbol;
|
|
8
|
-
declare global {
|
|
9
|
-
namespace GraphileConfig {
|
|
10
|
-
interface ResolvedPreset {
|
|
11
|
-
[$$hooksForPreset]?: null | AsyncHooks<GraphileConfig.GrafastHooks>;
|
|
12
|
-
[$$skipHooks]?: Record<string, boolean>;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export declare function withHooks<TResult>(resolvedPreset: GraphileConfig.ResolvedPreset, callback: (hooks: AsyncHooks<GraphileConfig.GrafastHooks> | null) => PromiseOrValue<TResult>): PromiseOrValue<TResult>;
|
|
17
|
-
export declare function hook<THookName extends keyof GraphileConfig.GrafastHooks>(resolvedPreset: GraphileConfig.ResolvedPreset, hookName: THookName, ...args: Parameters<GraphileConfig.GrafastHooks[THookName] extends PluginHook<infer U> ? U : never>): PromiseOrValue<void>;
|
|
18
|
-
export {};
|
|
19
2
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -1,99 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NULL_PRESET = void 0;
|
|
4
4
|
exports.NULL_PRESET = Object.freeze(Object.create(null));
|
|
5
|
-
let graphileConfig = undefined;
|
|
6
|
-
let graphileConfigLoaded = false;
|
|
7
|
-
function withGraphileConfig(callback) {
|
|
8
|
-
if (graphileConfig === undefined) {
|
|
9
|
-
// ESM:
|
|
10
|
-
// This should be
|
|
11
|
-
// graphileConfig = import("graphile-config").then(
|
|
12
|
-
// but that causes a segfault in jest/node when testing third party
|
|
13
|
-
// modules. So we had to convert everything to CommonJS.
|
|
14
|
-
graphileConfig = new Promise((resolve, reject) => {
|
|
15
|
-
try {
|
|
16
|
-
resolve(require("graphile-config"));
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
if (e.code === "ERR_REQUIRE_ESM") {
|
|
20
|
-
return import("graphile-config").then(resolve, reject);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}).then((GC) => {
|
|
27
|
-
graphileConfig = GC;
|
|
28
|
-
graphileConfigLoaded = true;
|
|
29
|
-
return GC;
|
|
30
|
-
}, () => {
|
|
31
|
-
graphileConfig = null;
|
|
32
|
-
graphileConfigLoaded = true;
|
|
33
|
-
return null;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
if (graphileConfigLoaded) {
|
|
37
|
-
return callback(graphileConfig);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return graphileConfig.then(callback);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.withGraphileConfig = withGraphileConfig;
|
|
44
|
-
const $$skipHooks = Symbol("skipHooks");
|
|
45
|
-
const $$hooksForPreset = Symbol("grafastHooks");
|
|
46
|
-
function withHooks(resolvedPreset, callback) {
|
|
47
|
-
const existing = resolvedPreset[$$hooksForPreset];
|
|
48
|
-
if (existing !== undefined) {
|
|
49
|
-
return callback(existing);
|
|
50
|
-
}
|
|
51
|
-
if (!resolvedPreset.plugins || resolvedPreset.plugins.length === 0) {
|
|
52
|
-
resolvedPreset[$$hooksForPreset] = null;
|
|
53
|
-
return callback(null);
|
|
54
|
-
}
|
|
55
|
-
const plugins = resolvedPreset.plugins;
|
|
56
|
-
return withGraphileConfig((gc) => {
|
|
57
|
-
if (gc !== null) {
|
|
58
|
-
const hooks = new gc.AsyncHooks();
|
|
59
|
-
gc.applyHooks(plugins, (p) => p.grafast?.hooks, (name, fn, _plugin) => {
|
|
60
|
-
hooks.hook(name, fn);
|
|
61
|
-
});
|
|
62
|
-
resolvedPreset[$$hooksForPreset] = hooks;
|
|
63
|
-
return callback(hooks);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
resolvedPreset[$$hooksForPreset] = null;
|
|
67
|
-
return callback(null);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
exports.withHooks = withHooks;
|
|
72
|
-
function hook(resolvedPreset, hookName, ...args) {
|
|
73
|
-
if (resolvedPreset[$$skipHooks]?.[hookName]) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
return withHooks(resolvedPreset, (hooks) => {
|
|
77
|
-
if (hooks !== null) {
|
|
78
|
-
if (hooks.callbacks[hookName] !== undefined) {
|
|
79
|
-
return hooks.process(hookName, ...args);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
if (!resolvedPreset[$$skipHooks]) {
|
|
83
|
-
resolvedPreset[$$skipHooks] = Object.create(null);
|
|
84
|
-
}
|
|
85
|
-
resolvedPreset[$$skipHooks][hookName] = true;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (!resolvedPreset[$$skipHooks]) {
|
|
91
|
-
resolvedPreset[$$skipHooks] = Object.create(null);
|
|
92
|
-
}
|
|
93
|
-
resolvedPreset[$$skipHooks][hookName] = true;
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
exports.hook = hook;
|
|
99
5
|
//# sourceMappingURL=config.js.map
|
package/dist/dev.js
CHANGED
|
@@ -19,9 +19,7 @@ if (typeof process !== "undefined" &&
|
|
|
19
19
|
typeof nodeEnv === "undefined") {
|
|
20
20
|
console.warn(`The GRAPHILE_ENV environmental variable is not set; Grafast will run in production mode. In your development environments, it's recommended that you set \`GRAPHILE_ENV=development\` to opt in to additional checks that will provide guidance and help you to catch issues in your code earlier, and other changes such as formatting to improve your development experience.`);
|
|
21
21
|
}
|
|
22
|
-
else if (exports.isDev && !exports.isTest) {
|
|
23
|
-
console.warn(`Grafast is running in development mode due to
|
|
24
|
-
? `GRAPHILE_ENV=${graphileEnv}`
|
|
25
|
-
: `NODE_ENV=${nodeEnv}`}\`; this is recommended for development environments (and strongly discouraged in production), but will impact on performance - in particular, planning will be significantly more expensive.`);
|
|
22
|
+
else if (exports.isDev && !exports.isTest && typeof graphileEnv === "undefined") {
|
|
23
|
+
console.warn(`Grafast is running in development mode due to \`NODE_ENV=${nodeEnv}\`; this is recommended for development environments (and strongly discouraged in production), but will impact on performance - in particular, planning will be significantly more expensive. To remove this warning, make this explicit with \`GRAPHILE_ENV=development\` envvar.`);
|
|
26
24
|
}
|
|
27
25
|
//# sourceMappingURL=dev.js.map
|
|
@@ -62,7 +62,8 @@ function executeBucket(bucket, requestContext) {
|
|
|
62
62
|
return { flags, results };
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
const { stopTime, eventEmitter } = requestContext;
|
|
65
|
+
const { stopTime, eventEmitter, args } = requestContext;
|
|
66
|
+
const { middleware } = args;
|
|
66
67
|
const { metaByMetaKey, size, store, layerPlan: { phases, children: childLayerPlans }, } = bucket;
|
|
67
68
|
const phaseCount = phases.length;
|
|
68
69
|
let sideEffectStepsWithErrors = null;
|
|
@@ -574,26 +575,38 @@ function executeBucket(bucket, requestContext) {
|
|
|
574
575
|
if (step.stream.length > 1) {
|
|
575
576
|
throw new Error(`${step} is using a legacy form of 'stream' which accepts multiple arguments, please see https://err.red/gev2`);
|
|
576
577
|
}
|
|
577
|
-
|
|
578
|
+
const streamDetails = {
|
|
578
579
|
indexMap: makeIndexMap(count),
|
|
579
580
|
indexForEach: makeIndexForEach(count),
|
|
580
581
|
count,
|
|
581
582
|
values,
|
|
582
583
|
extra,
|
|
583
584
|
streamOptions,
|
|
584
|
-
}
|
|
585
|
+
};
|
|
586
|
+
if (!step.isSyncAndSafe && middleware != null) {
|
|
587
|
+
return middleware.run("streamStep", { args, step, streamDetails }, streamStepFromEvent);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
return step.stream(streamDetails);
|
|
591
|
+
}
|
|
585
592
|
}
|
|
586
593
|
else {
|
|
587
594
|
if (step.execute.length > 1) {
|
|
588
595
|
throw new Error(`${step} is using a legacy form of 'execute' which accepts multiple arguments, please see https://err.red/gev2`);
|
|
589
596
|
}
|
|
590
|
-
|
|
597
|
+
const executeDetails = {
|
|
591
598
|
indexMap: makeIndexMap(count),
|
|
592
599
|
indexForEach: makeIndexForEach(count),
|
|
593
600
|
count,
|
|
594
601
|
values,
|
|
595
602
|
extra,
|
|
596
|
-
}
|
|
603
|
+
};
|
|
604
|
+
if (!step.isSyncAndSafe && middleware != null) {
|
|
605
|
+
return middleware.run("executeStep", { args, step, executeDetails }, executeStepFromEvent);
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
return step.execute(executeDetails);
|
|
609
|
+
}
|
|
597
610
|
}
|
|
598
611
|
}
|
|
599
612
|
// Slow mode...
|
|
@@ -1080,4 +1093,10 @@ function makeIndexForEach(count) {
|
|
|
1080
1093
|
}
|
|
1081
1094
|
return result;
|
|
1082
1095
|
}
|
|
1096
|
+
function streamStepFromEvent(event) {
|
|
1097
|
+
return event.step.stream(event.streamDetails);
|
|
1098
|
+
}
|
|
1099
|
+
function executeStepFromEvent(event) {
|
|
1100
|
+
return event.step.execute(event.executeDetails);
|
|
1101
|
+
}
|
|
1083
1102
|
//# sourceMappingURL=executeBucket.js.map
|
package/dist/execute.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ import type { GrafastExecutionArgs } from "./interfaces.js";
|
|
|
5
5
|
* @deprecated Second and third parameters should be passed as part of args,
|
|
6
6
|
* specifically `resolvedPreset` and `outputDataAsString`.
|
|
7
7
|
*/
|
|
8
|
-
export declare function execute(args:
|
|
8
|
+
export declare function execute(args: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset | undefined, outputDataAsString?: boolean): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
|
|
9
9
|
/**
|
|
10
10
|
* Use this instead of GraphQL.js' execute method and we'll automatically
|
|
11
11
|
* run grafastPrepare for you and handle the result.
|
|
12
12
|
*/
|
|
13
|
-
export declare function execute(args:
|
|
13
|
+
export declare function execute(args: GrafastExecutionArgs): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
|
|
14
14
|
//# sourceMappingURL=execute.d.ts.map
|
package/dist/execute.js
CHANGED
|
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.execute = exports.withGrafastArgs = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const eventemitter3_1 = tslib_1.__importDefault(require("eventemitter3"));
|
|
6
|
-
const config_js_1 = require("./config.js");
|
|
7
6
|
const dev_js_1 = require("./dev.js");
|
|
8
7
|
const inspect_js_1 = require("./inspect.js");
|
|
9
8
|
const interfaces_js_1 = require("./interfaces.js");
|
|
9
|
+
const middleware_js_1 = require("./middleware.js");
|
|
10
10
|
const prepare_js_1 = require("./prepare.js");
|
|
11
11
|
const utils_js_1 = require("./utils.js");
|
|
12
12
|
/**
|
|
13
13
|
* Used by `execute` and `subscribe`.
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
|
-
function withGrafastArgs(args
|
|
17
|
-
const options = resolvedPreset?.grafast;
|
|
16
|
+
function withGrafastArgs(args) {
|
|
17
|
+
const options = args.resolvedPreset?.grafast;
|
|
18
18
|
if (dev_js_1.isDev) {
|
|
19
19
|
if (args.rootValue != null &&
|
|
20
20
|
(typeof args.rootValue !== "object" ||
|
|
@@ -54,8 +54,9 @@ function withGrafastArgs(args, resolvedPreset, outputDataAsString) {
|
|
|
54
54
|
}
|
|
55
55
|
const rootValue = (0, prepare_js_1.grafastPrepare)(args, {
|
|
56
56
|
explain: options?.explain,
|
|
57
|
-
outputDataAsString,
|
|
58
57
|
timeouts: options?.timeouts,
|
|
58
|
+
// TODO: Delete this
|
|
59
|
+
outputDataAsString: args.outputDataAsString,
|
|
59
60
|
});
|
|
60
61
|
if (unlisten !== null) {
|
|
61
62
|
Promise.resolve(rootValue).then(unlisten, unlisten);
|
|
@@ -69,8 +70,28 @@ function withGrafastArgs(args, resolvedPreset, outputDataAsString) {
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
exports.withGrafastArgs = withGrafastArgs;
|
|
72
|
-
function execute(args,
|
|
73
|
-
|
|
73
|
+
function execute(args, legacyResolvedPreset, legacyOutputDataAsString) {
|
|
74
|
+
// TODO: remove legacy compatibility
|
|
75
|
+
if (legacyResolvedPreset !== undefined) {
|
|
76
|
+
args.resolvedPreset = legacyResolvedPreset;
|
|
77
|
+
}
|
|
78
|
+
if (legacyOutputDataAsString !== undefined) {
|
|
79
|
+
args.outputDataAsString = legacyOutputDataAsString;
|
|
80
|
+
}
|
|
81
|
+
const { resolvedPreset } = args;
|
|
82
|
+
const middleware = args.middleware === undefined && resolvedPreset != null
|
|
83
|
+
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
|
|
84
|
+
: args.middleware ?? null;
|
|
85
|
+
if (args.middleware === undefined) {
|
|
86
|
+
args.middleware = middleware;
|
|
87
|
+
}
|
|
88
|
+
if (middleware !== null) {
|
|
89
|
+
return middleware.run("execute", { args }, executeMiddlewareCallback);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return withGrafastArgs(args);
|
|
93
|
+
}
|
|
74
94
|
}
|
|
75
95
|
exports.execute = execute;
|
|
96
|
+
const executeMiddlewareCallback = (event) => withGrafastArgs(event.args);
|
|
76
97
|
//# sourceMappingURL=execute.js.map
|
package/dist/grafastGraphql.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { AsyncExecutionResult, ExecutionResult } from "graphql";
|
|
2
2
|
import type { PromiseOrValue } from "graphql/jsutils/PromiseOrValue";
|
|
3
3
|
import type { GrafastArgs } from "./interfaces.js";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Second and third parameters should be passed as part of args,
|
|
6
|
+
* specifically `resolvedPreset` and `requestContext`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function grafast(args: GrafastArgs, legacyResolvedPreset?: GraphileConfig.ResolvedPreset, legacyCtx?: Partial<Grafast.RequestContext>): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
|
|
4
9
|
/**
|
|
5
10
|
* A replacement for GraphQL.js' `graphql` method that calls Grafast's
|
|
6
11
|
* execute instead
|
|
7
12
|
*/
|
|
8
|
-
export declare function grafast(args: GrafastArgs
|
|
13
|
+
export declare function grafast(args: GrafastArgs): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
|
|
9
14
|
export declare function grafastSync(args: GrafastArgs, legacyResolvedPreset?: GraphileConfig.ResolvedPreset, legacyRequestContext?: Partial<Grafast.RequestContext>): ExecutionResult;
|
|
10
15
|
//# sourceMappingURL=grafastGraphql.d.ts.map
|
package/dist/grafastGraphql.js
CHANGED
|
@@ -8,6 +8,7 @@ const error_js_1 = require("./error.js");
|
|
|
8
8
|
const execute_js_1 = require("./execute.js");
|
|
9
9
|
const index_js_1 = require("./index.js");
|
|
10
10
|
const interfaces_js_1 = require("./interfaces.js");
|
|
11
|
+
const middleware_js_1 = require("./middleware.js");
|
|
11
12
|
const utils_js_1 = require("./utils.js");
|
|
12
13
|
const { GraphQLError, parse, Source, validate, validateSchema } = graphql;
|
|
13
14
|
/** Rough average size per query */
|
|
@@ -79,19 +80,31 @@ const parseAndValidate = (gqlSchema, stringOrSource) => {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
|
-
/**
|
|
83
|
-
* A replacement for GraphQL.js' `graphql` method that calls Grafast's
|
|
84
|
-
* execute instead
|
|
85
|
-
*/
|
|
86
83
|
function grafast(args, legacyResolvedPreset, legacyCtx) {
|
|
87
|
-
|
|
84
|
+
// Convert legacy args to properties on `args`:
|
|
85
|
+
if (legacyResolvedPreset !== undefined) {
|
|
86
|
+
args.resolvedPreset = args.resolvedPreset ?? legacyResolvedPreset;
|
|
87
|
+
}
|
|
88
|
+
if (legacyCtx !== undefined) {
|
|
89
|
+
args.requestContext = args.requestContext ?? legacyCtx;
|
|
90
|
+
}
|
|
91
|
+
const { schema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver, resolvedPreset, requestContext, middleware: rawMiddleware, } = args;
|
|
92
|
+
const middleware = rawMiddleware !== undefined
|
|
93
|
+
? rawMiddleware
|
|
94
|
+
: resolvedPreset != null
|
|
95
|
+
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
|
|
96
|
+
: null;
|
|
88
97
|
// Validate Schema
|
|
89
|
-
const schemaValidationErrors =
|
|
98
|
+
const schemaValidationErrors = middleware != null && resolvedPreset != null
|
|
99
|
+
? middleware.runSync("validateSchema", { schema, resolvedPreset }, validateSchemaWithEvent)
|
|
100
|
+
: validateSchema(schema);
|
|
90
101
|
if (schemaValidationErrors.length > 0) {
|
|
91
102
|
return { errors: schemaValidationErrors };
|
|
92
103
|
}
|
|
93
104
|
// Cached parse and validate
|
|
94
|
-
const documentOrErrors =
|
|
105
|
+
const documentOrErrors = middleware != null && resolvedPreset != null
|
|
106
|
+
? middleware.runSync("parseAndValidate", { resolvedPreset, schema, source }, parseAndValidateWithEvent)
|
|
107
|
+
: parseAndValidate(schema, source);
|
|
95
108
|
if (Array.isArray(documentOrErrors)) {
|
|
96
109
|
return { errors: documentOrErrors };
|
|
97
110
|
}
|
|
@@ -105,20 +118,21 @@ function grafast(args, legacyResolvedPreset, legacyCtx) {
|
|
|
105
118
|
operationName,
|
|
106
119
|
fieldResolver,
|
|
107
120
|
typeResolver,
|
|
121
|
+
middleware,
|
|
122
|
+
resolvedPreset,
|
|
123
|
+
requestContext,
|
|
108
124
|
};
|
|
109
125
|
if (resolvedPreset && requestContext) {
|
|
110
|
-
const argsOrPromise = (0, index_js_1.hookArgs)(executionArgs
|
|
126
|
+
const argsOrPromise = (0, index_js_1.hookArgs)(executionArgs);
|
|
111
127
|
if ((0, utils_js_1.isPromiseLike)(argsOrPromise)) {
|
|
112
|
-
return Promise.resolve(argsOrPromise).then(
|
|
128
|
+
return Promise.resolve(argsOrPromise).then(execute_js_1.execute);
|
|
113
129
|
}
|
|
114
130
|
else {
|
|
115
|
-
|
|
116
|
-
return (0, execute_js_1.execute)(argsOrPromise, resolvedPreset);
|
|
131
|
+
return (0, execute_js_1.execute)(argsOrPromise);
|
|
117
132
|
}
|
|
118
133
|
}
|
|
119
134
|
else {
|
|
120
|
-
|
|
121
|
-
return (0, execute_js_1.execute)(executionArgs, resolvedPreset);
|
|
135
|
+
return (0, execute_js_1.execute)(executionArgs);
|
|
122
136
|
}
|
|
123
137
|
}
|
|
124
138
|
exports.grafast = grafast;
|
|
@@ -130,4 +144,10 @@ function grafastSync(args, legacyResolvedPreset, legacyRequestContext) {
|
|
|
130
144
|
return result;
|
|
131
145
|
}
|
|
132
146
|
exports.grafastSync = grafastSync;
|
|
147
|
+
function validateSchemaWithEvent(event) {
|
|
148
|
+
return validateSchema(event.schema);
|
|
149
|
+
}
|
|
150
|
+
function parseAndValidateWithEvent(event) {
|
|
151
|
+
return parseAndValidate(event.schema, event.source);
|
|
152
|
+
}
|
|
133
153
|
//# sourceMappingURL=grafastGraphql.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./thereCanBeOnlyOne.js";
|
|
2
2
|
import type LRU from "@graphile/lru";
|
|
3
|
-
import type {
|
|
4
|
-
import type { DocumentNode,
|
|
3
|
+
import type { CallbackOrDescriptor, MiddlewareNext } from "graphile-config";
|
|
4
|
+
import type { DocumentNode, GraphQLError, OperationDefinitionNode } from "graphql";
|
|
5
5
|
import type { DataFromObjectSteps } from "./steps/object.js";
|
|
6
6
|
type PromiseOrValue<T> = T | Promise<T>;
|
|
7
7
|
import { exportAs, exportAsMany } from "./exportAs.js";
|
|
@@ -14,8 +14,9 @@ import { OperationPlan } from "./engine/OperationPlan.js";
|
|
|
14
14
|
import { $$inhibit, flagError, isSafeError, SafeError } from "./error.js";
|
|
15
15
|
import { execute } from "./execute.js";
|
|
16
16
|
import { grafast, grafastSync } from "./grafastGraphql.js";
|
|
17
|
-
import type { $$cacheByOperation, $$hooked, $$queryCache, CacheByOperationEntry, DataFromStep, GrafastExecutionArgs, GrafastTimeouts, ScalarInputPlanResolver } from "./interfaces.js";
|
|
17
|
+
import type { $$cacheByOperation, $$hooked, $$queryCache, CacheByOperationEntry, DataFromStep, EstablishOperationPlanEvent, ExecuteEvent, ExecuteStepEvent, GrafastExecutionArgs, GrafastTimeouts, ParseAndValidateEvent, PrepareArgsEvent, ScalarInputPlanResolver, StreamStepEvent, ValidateSchemaEvent } from "./interfaces.js";
|
|
18
18
|
import { $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$verbatim, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, EnumValueApplyPlanResolver, EventCallback, EventMapKey, ExecutionDetails, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, FieldArgs, FieldInfo, FieldPlanResolver, GrafastArgumentConfig, GrafastFieldConfig, GrafastFieldConfigArgumentMap, GrafastInputFieldConfig, GrafastPlanJSON, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, GrafastValuesList, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, InputObjectTypeInputPlanResolver, InputStep, JSONArray, JSONObject, JSONValue, Maybe, NodeIdCodec, NodeIdHandler, OutputPlanForType, PolymorphicData, PromiseOrDirect, ScalarPlanResolver, StepOptimizeOptions, StepStreamOptions, TypedEventEmitter, UnbatchedExecutionExtra } from "./interfaces.js";
|
|
19
|
+
import { getGrafastMiddleware } from "./middleware.js";
|
|
19
20
|
import { polymorphicWrap } from "./polymorphic.js";
|
|
20
21
|
import { assertExecutableStep, assertListCapableStep, assertModifierStep, BaseStep, ExecutableStep, isExecutableStep, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isStreamableStep, ListCapableStep, ListLikeStep, ModifierStep, ObjectLikeStep, PolymorphicStep, StreamableStep, UnbatchedExecutableStep } from "./step.js";
|
|
21
22
|
import { __FlagStep, __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, access, AccessStep, ActualKeyByDesiredKey, applyTransforms, ApplyTransformsStep, assertEdgeCapableStep, assertNotNull, assertPageInfoCapableStep, condition, ConditionStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, debugPlans, each, EdgeCapableStep, EdgeStep, error, ErrorStep, filter, FilterPlanMemo, first, FirstStep, GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, inhibitOnNull, lambda, LambdaStep, last, LastStep, list, listen, ListenStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, node, nodeIdFromNode, NodeStep, object, ObjectPlanMeta, ObjectStep, operationPlan, PageInfoCapableStep, partitionByIndex, polymorphicBranch, PolymorphicBranchMatcher, PolymorphicBranchMatchers, PolymorphicBranchStep, proxy, ProxyStep, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, rootValue, setter, SetterCapableStep, SetterStep, sideEffect, SideEffectStep, specFromNodeId, trackedContext, trackedRootValue, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED } from "./steps/index.js";
|
|
@@ -24,7 +25,7 @@ import { stripAnsi } from "./stripAnsi.js";
|
|
|
24
25
|
import { subscribe } from "./subscribe.js";
|
|
25
26
|
import { arrayOfLength, arraysMatch, getEnumValueConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, inputObjectFieldSpec, InputObjectTypeSpec, isPromiseLike, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, objectFieldSpec, objectSpec, ObjectTypeFields, ObjectTypeSpec, stepADependsOnStepB, stepAMayDependOnStepB, stepsAreInSamePhase } from "./utils.js";
|
|
26
27
|
export { isAsyncIterable } from "iterall";
|
|
27
|
-
export { __FlagStep, __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$inhibit, $$verbatim, access, AccessStep, ActualKeyByDesiredKey, applyTransforms, ApplyTransformsStep, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, arrayOfLength, arraysMatch, assertEdgeCapableStep, assertExecutableStep, assertListCapableStep, assertModifierStep, assertNotNull, assertPageInfoCapableStep, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, BaseStep, condition, ConditionStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, DataFromObjectSteps, DataFromStep, debugPlans, defer, Deferred, each, EdgeCapableStep, EdgeStep, EnumPlans, EnumValueApplyPlanResolver, error, ErrorStep, EventCallback, EventMapKey, ExecutableStep, execute, ExecutionDetails, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, exportAs, exportAsMany, FieldArgs, FieldInfo, FieldPlanResolver, FieldPlans, filter, FilterPlanMemo, first, FirstStep, flagError, getEnumValueConfig, grafast, GrafastArgumentConfig, GrafastExecutionArgs, GrafastFieldConfig, GrafastFieldConfigArgumentMap, grafast as grafastGraphql, grafastSync as grafastGraphqlSync, GrafastInputFieldConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, GrafastPlanJSON, GrafastPlans, grafastPrint, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, grafastSync, GrafastValuesList, GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, inhibitOnNull, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, inputObjectFieldSpec, InputObjectPlans, InputObjectTypeInputPlanResolver, InputObjectTypeSpec, InputStep, InterfaceOrUnionPlans, isDev, isExecutableStep, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isPromiseLike, isSafeError, isStreamableStep, isUnaryStep, JSONArray, JSONObject, JSONValue, lambda, LambdaStep, last, LastStep, list, ListCapableStep, listen, ListenStep, ListLikeStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, makeGrafastSchema, Maybe, ModifierStep, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, node, NodeIdCodec, nodeIdFromNode, NodeIdHandler, NodeStep, noop, object, objectFieldSpec, ObjectLikeStep, ObjectPlanMeta, ObjectPlans, objectSpec, ObjectStep, ObjectTypeFields, ObjectTypeSpec, OperationPlan, operationPlan, OutputPlanForType, PageInfoCapableStep, partitionByIndex, polymorphicBranch, PolymorphicBranchMatcher, PolymorphicBranchMatchers, PolymorphicBranchStep, PolymorphicData, PolymorphicStep, polymorphicWrap, PromiseOrDirect, proxy, ProxyStep, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, rootValue, SafeError, ScalarPlanResolver, ScalarPlans, setter, SetterCapableStep, SetterStep, sideEffect, SideEffectStep, specFromNodeId, stepADependsOnStepB, stepAMayDependOnStepB, StepOptimizeOptions, stepsAreInSamePhase, StepStreamOptions, StreamableStep, stringifyPayload, stripAnsi, subscribe, trackedContext, trackedRootValue, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED, TypedEventEmitter, UnbatchedExecutableStep, UnbatchedExecutionExtra, };
|
|
28
|
+
export { __FlagStep, __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$inhibit, $$verbatim, access, AccessStep, ActualKeyByDesiredKey, applyTransforms, ApplyTransformsStep, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, arrayOfLength, arraysMatch, assertEdgeCapableStep, assertExecutableStep, assertListCapableStep, assertModifierStep, assertNotNull, assertPageInfoCapableStep, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, BaseStep, condition, ConditionStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, DataFromObjectSteps, DataFromStep, debugPlans, defer, Deferred, each, EdgeCapableStep, EdgeStep, EnumPlans, EnumValueApplyPlanResolver, error, ErrorStep, EventCallback, EventMapKey, ExecutableStep, execute, ExecutionDetails, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, exportAs, exportAsMany, FieldArgs, FieldInfo, FieldPlanResolver, FieldPlans, filter, FilterPlanMemo, first, FirstStep, flagError, getEnumValueConfig, getGrafastMiddleware, grafast, GrafastArgumentConfig, GrafastExecutionArgs, GrafastFieldConfig, GrafastFieldConfigArgumentMap, grafast as grafastGraphql, grafastSync as grafastGraphqlSync, GrafastInputFieldConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, GrafastPlanJSON, GrafastPlans, grafastPrint, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, grafastSync, GrafastValuesList, GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, inhibitOnNull, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, inputObjectFieldSpec, InputObjectPlans, InputObjectTypeInputPlanResolver, InputObjectTypeSpec, InputStep, InterfaceOrUnionPlans, isDev, isExecutableStep, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isPromiseLike, isSafeError, isStreamableStep, isUnaryStep, JSONArray, JSONObject, JSONValue, lambda, LambdaStep, last, LastStep, list, ListCapableStep, listen, ListenStep, ListLikeStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, makeGrafastSchema, Maybe, ModifierStep, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, node, NodeIdCodec, nodeIdFromNode, NodeIdHandler, NodeStep, noop, object, objectFieldSpec, ObjectLikeStep, ObjectPlanMeta, ObjectPlans, objectSpec, ObjectStep, ObjectTypeFields, ObjectTypeSpec, OperationPlan, operationPlan, OutputPlanForType, PageInfoCapableStep, partitionByIndex, polymorphicBranch, PolymorphicBranchMatcher, PolymorphicBranchMatchers, PolymorphicBranchStep, PolymorphicData, PolymorphicStep, polymorphicWrap, PromiseOrDirect, proxy, ProxyStep, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, rootValue, SafeError, ScalarPlanResolver, ScalarPlans, setter, SetterCapableStep, SetterStep, sideEffect, SideEffectStep, specFromNodeId, stepADependsOnStepB, stepAMayDependOnStepB, StepOptimizeOptions, stepsAreInSamePhase, StepStreamOptions, StreamableStep, stringifyPayload, stripAnsi, subscribe, trackedContext, trackedRootValue, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED, TypedEventEmitter, UnbatchedExecutableStep, UnbatchedExecutionExtra, };
|
|
28
29
|
export { hookArgs } from "./args.js";
|
|
29
30
|
export { version } from "./version.js";
|
|
30
31
|
/** @deprecated Renamed to 'applyTransforms' */
|
|
@@ -33,7 +34,7 @@ export declare const deepEval: typeof applyTransforms;
|
|
|
33
34
|
export declare const DeepEvalStep: typeof ApplyTransformsStep;
|
|
34
35
|
declare global {
|
|
35
36
|
namespace Grafast {
|
|
36
|
-
type ExecutionArgs = Pick<
|
|
37
|
+
type ExecutionArgs = Pick<GrafastExecutionArgs, "schema" | "document" | "rootValue" | "variableValues" | "operationName" | "resolvedPreset" | "middleware" | "requestContext" | "outputDataAsString"> & {
|
|
37
38
|
[$$hooked]?: boolean;
|
|
38
39
|
contextValue: Grafast.Context;
|
|
39
40
|
};
|
|
@@ -142,16 +143,24 @@ declare global {
|
|
|
142
143
|
*/
|
|
143
144
|
grafast?: GraphileConfig.GrafastOptions;
|
|
144
145
|
}
|
|
145
|
-
interface
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
interface GrafastMiddleware {
|
|
147
|
+
/** Synchronous! */
|
|
148
|
+
validateSchema(event: ValidateSchemaEvent): readonly GraphQLError[];
|
|
149
|
+
/** Synchronous! */
|
|
150
|
+
parseAndValidate(event: ParseAndValidateEvent): DocumentNode | readonly GraphQLError[];
|
|
151
|
+
prepareArgs(event: PrepareArgsEvent): PromiseOrDirect<Grafast.ExecutionArgs>;
|
|
152
|
+
execute(event: ExecuteEvent): ReturnType<typeof execute>;
|
|
153
|
+
subscribe(event: ExecuteEvent): ReturnType<typeof subscribe>;
|
|
154
|
+
/** Synchronous! */
|
|
155
|
+
establishOperationPlan(event: EstablishOperationPlanEvent): OperationPlan;
|
|
156
|
+
executeStep(event: ExecuteStepEvent): PromiseOrDirect<GrafastResultsList<any>>;
|
|
157
|
+
streamStep(event: StreamStepEvent): PromiseOrDirect<GrafastResultStreamList<unknown>>;
|
|
151
158
|
}
|
|
152
159
|
interface Plugin {
|
|
153
160
|
grafast?: {
|
|
154
|
-
|
|
161
|
+
middleware?: {
|
|
162
|
+
[key in keyof GrafastMiddleware]?: CallbackOrDescriptor<GrafastMiddleware[key] extends (...args: infer UArgs) => infer UResult ? (next: MiddlewareNext<Awaited<UResult>>, ...args: UArgs) => UResult : never>;
|
|
163
|
+
};
|
|
155
164
|
};
|
|
156
165
|
}
|
|
157
166
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEnumValueConfig = exports.flagError = exports.FirstStep = exports.first = exports.filter = exports.exportAsMany = exports.exportAs = exports.execute = exports.ExecutableStep = exports.ErrorStep = exports.error = exports.EdgeStep = exports.each = exports.defer = exports.debugPlans = exports.context = exports.ConstantStep = exports.constant = exports.ConnectionStep = exports.connection = exports.ConditionStep = exports.condition = exports.BaseStep = exports.assertPageInfoCapableStep = exports.assertNotNull = exports.assertModifierStep = exports.assertListCapableStep = exports.assertExecutableStep = exports.assertEdgeCapableStep = exports.arraysMatch = exports.arrayOfLength = exports.ApplyTransformsStep = exports.applyTransforms = exports.AccessStep = exports.access = exports.$$verbatim = exports.$$inhibit = exports.$$idempotent = exports.$$extensions = exports.$$eventEmitter = exports.$$bypassGraphQL = exports.__ValueStep = exports.__TrackedValueStep = exports.__ListTransformStep = exports.__ItemStep = exports.__InputStaticLeafStep = exports.__InputObjectStep = exports.__InputListStep = exports.__FlagStep = exports.isAsyncIterable = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.DeepEvalStep = exports.deepEval = exports.version = exports.hookArgs = exports.UnbatchedExecutableStep = exports.TRAP_INHIBITED = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_ERROR = exports.trap = exports.trackedRootValue = exports.trackedContext = exports.subscribe = exports.stripAnsi = exports.stringifyPayload = exports.stepsAreInSamePhase = exports.stepAMayDependOnStepB = exports.stepADependsOnStepB = exports.specFromNodeId = exports.SideEffectStep = exports.sideEffect = exports.SetterStep = exports.setter = exports.SafeError = exports.rootValue = exports.ReverseStep = exports.reverseArray = exports.reverse = exports.RemapKeysStep = exports.remapKeys = exports.ProxyStep = exports.proxy = exports.polymorphicWrap = exports.PolymorphicBranchStep = exports.polymorphicBranch = exports.partitionByIndex = exports.operationPlan = exports.OperationPlan = exports.ObjectStep = void 0;
|
|
4
|
+
exports.objectFieldSpec = exports.object = exports.noop = exports.NodeStep = exports.nodeIdFromNode = exports.node = exports.newObjectTypeBuilder = exports.newInputObjectTypeBuilder = exports.newGrafastFieldConfigBuilder = exports.ModifierStep = exports.makeGrafastSchema = exports.makeDecodeNodeId = exports.LoadStep = exports.loadOneCallback = exports.loadOne = exports.loadManyCallback = exports.loadMany = exports.LoadedRecordStep = exports.listTransform = exports.ListStep = exports.ListenStep = exports.listen = exports.list = exports.LastStep = exports.last = exports.LambdaStep = exports.lambda = exports.isUnaryStep = exports.isStreamableStep = exports.isSafeError = exports.isPromiseLike = exports.isObjectLikeStep = exports.isModifierStep = exports.isListLikeStep = exports.isListCapableStep = exports.isExecutableStep = exports.isDev = exports.inputObjectFieldSpec = exports.inhibitOnNull = exports.groupBy = exports.GraphQLResolverStep = exports.graphqlResolver = exports.graphqlItemHandler = exports.GraphQLItemHandler = exports.grafastSync = exports.grafastPrint = exports.grafastGraphqlSync = exports.grafastGraphql = exports.grafast = exports.getGrafastMiddleware = void 0;
|
|
5
|
+
exports.DeepEvalStep = exports.deepEval = exports.version = exports.hookArgs = exports.UnbatchedExecutableStep = exports.TRAP_INHIBITED = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_ERROR = exports.trap = exports.trackedRootValue = exports.trackedContext = exports.subscribe = exports.stripAnsi = exports.stringifyPayload = exports.stepsAreInSamePhase = exports.stepAMayDependOnStepB = exports.stepADependsOnStepB = exports.specFromNodeId = exports.SideEffectStep = exports.sideEffect = exports.SetterStep = exports.setter = exports.SafeError = exports.rootValue = exports.ReverseStep = exports.reverseArray = exports.reverse = exports.RemapKeysStep = exports.remapKeys = exports.ProxyStep = exports.proxy = exports.polymorphicWrap = exports.PolymorphicBranchStep = exports.polymorphicBranch = exports.partitionByIndex = exports.operationPlan = exports.OperationPlan = exports.ObjectStep = exports.objectSpec = void 0;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
require("./thereCanBeOnlyOne.js");
|
|
8
8
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
@@ -43,6 +43,8 @@ Object.defineProperty(exports, "$$eventEmitter", { enumerable: true, get: functi
|
|
|
43
43
|
Object.defineProperty(exports, "$$extensions", { enumerable: true, get: function () { return interfaces_js_1.$$extensions; } });
|
|
44
44
|
Object.defineProperty(exports, "$$idempotent", { enumerable: true, get: function () { return interfaces_js_1.$$idempotent; } });
|
|
45
45
|
Object.defineProperty(exports, "$$verbatim", { enumerable: true, get: function () { return interfaces_js_1.$$verbatim; } });
|
|
46
|
+
const middleware_js_1 = require("./middleware.js");
|
|
47
|
+
Object.defineProperty(exports, "getGrafastMiddleware", { enumerable: true, get: function () { return middleware_js_1.getGrafastMiddleware; } });
|
|
46
48
|
const polymorphic_js_1 = require("./polymorphic.js");
|
|
47
49
|
Object.defineProperty(exports, "polymorphicWrap", { enumerable: true, get: function () { return polymorphic_js_1.polymorphicWrap; } });
|
|
48
50
|
const step_js_1 = require("./step.js");
|
|
@@ -170,6 +172,7 @@ Object.defineProperty(exports, "isAsyncIterable", { enumerable: true, get: funct
|
|
|
170
172
|
OperationPlan: OperationPlan_js_1.OperationPlan,
|
|
171
173
|
defer: deferred_js_1.defer,
|
|
172
174
|
execute: execute_js_1.execute,
|
|
175
|
+
getGrafastMiddleware: middleware_js_1.getGrafastMiddleware,
|
|
173
176
|
grafast: grafastGraphql_js_1.grafast,
|
|
174
177
|
grafastSync: grafastGraphql_js_1.grafastSync,
|
|
175
178
|
subscribe: subscribe_js_1.subscribe,
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type EventEmitter from "eventemitter3";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Middleware } from "graphile-config";
|
|
3
|
+
import type { ASTNode, ExecutionArgs, FragmentDefinitionNode, GraphQLArgs, GraphQLArgument, GraphQLArgumentConfig, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLList, GraphQLNonNull, GraphQLOutputType, GraphQLScalarType, GraphQLSchema, GraphQLType, OperationDefinitionNode, Source, ValueNode, VariableNode } from "graphql";
|
|
4
|
+
import type { ObjMap } from "graphql/jsutils/ObjMap.js";
|
|
3
5
|
import type { OperationPlan } from "./engine/OperationPlan.js";
|
|
4
6
|
import type { FlaggedValue, SafeError } from "./error.js";
|
|
5
|
-
import type { ExecutableStep, ListCapableStep, ModifierStep } from "./step.js";
|
|
7
|
+
import type { ExecutableStep, ListCapableStep, ModifierStep, StreamableStep } from "./step.js";
|
|
6
8
|
import type { __InputDynamicScalarStep } from "./steps/__inputDynamicScalar.js";
|
|
7
9
|
import type { __InputListStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __TrackedValueStep, __TrackedValueStepWithDollars, ConstantStep } from "./steps/index.js";
|
|
8
10
|
import type { GrafastInputObjectType, GrafastObjectType } from "./utils.js";
|
|
@@ -461,6 +463,7 @@ export type StreamMoreableArray<T = any> = Array<T> & {
|
|
|
461
463
|
export interface GrafastArgs extends GraphQLArgs {
|
|
462
464
|
resolvedPreset?: GraphileConfig.ResolvedPreset;
|
|
463
465
|
requestContext?: Partial<Grafast.RequestContext>;
|
|
466
|
+
middleware?: Middleware<GraphileConfig.GrafastMiddleware> | null;
|
|
464
467
|
}
|
|
465
468
|
export type Maybe<T> = T | null | undefined;
|
|
466
469
|
export * from "./planJSONInterfaces.js";
|
|
@@ -474,6 +477,46 @@ export interface AddDependencyOptions {
|
|
|
474
477
|
export type DataFromStep<TStep extends ExecutableStep> = TStep extends ExecutableStep<infer TData> ? TData : never;
|
|
475
478
|
export interface GrafastExecutionArgs extends ExecutionArgs {
|
|
476
479
|
resolvedPreset?: GraphileConfig.ResolvedPreset;
|
|
480
|
+
middleware?: Middleware<GraphileConfig.GrafastMiddleware> | null;
|
|
481
|
+
requestContext?: Partial<Grafast.RequestContext>;
|
|
477
482
|
outputDataAsString?: boolean;
|
|
478
483
|
}
|
|
484
|
+
export interface ValidateSchemaEvent {
|
|
485
|
+
resolvedPreset: GraphileConfig.ResolvedPreset;
|
|
486
|
+
schema: GraphQLSchema;
|
|
487
|
+
}
|
|
488
|
+
export interface ParseAndValidateEvent {
|
|
489
|
+
resolvedPreset: GraphileConfig.ResolvedPreset;
|
|
490
|
+
schema: GraphQLSchema;
|
|
491
|
+
source: string | Source;
|
|
492
|
+
}
|
|
493
|
+
export interface PrepareArgsEvent {
|
|
494
|
+
args: Grafast.ExecutionArgs;
|
|
495
|
+
}
|
|
496
|
+
export interface ExecuteEvent {
|
|
497
|
+
args: GrafastExecutionArgs;
|
|
498
|
+
}
|
|
499
|
+
export interface SubscribeEvent {
|
|
500
|
+
args: GrafastExecutionArgs;
|
|
501
|
+
}
|
|
502
|
+
export interface EstablishOperationPlanEvent {
|
|
503
|
+
schema: GraphQLSchema;
|
|
504
|
+
operation: OperationDefinitionNode;
|
|
505
|
+
fragments: ObjMap<FragmentDefinitionNode>;
|
|
506
|
+
variableValues: Record<string, any>;
|
|
507
|
+
context: any;
|
|
508
|
+
rootValue: any;
|
|
509
|
+
planningTimeout: number | undefined;
|
|
510
|
+
args: GrafastExecutionArgs;
|
|
511
|
+
}
|
|
512
|
+
export interface ExecuteStepEvent {
|
|
513
|
+
args: GrafastExecutionArgs;
|
|
514
|
+
step: ExecutableStep;
|
|
515
|
+
executeDetails: ExecutionDetails;
|
|
516
|
+
}
|
|
517
|
+
export interface StreamStepEvent {
|
|
518
|
+
args: GrafastExecutionArgs;
|
|
519
|
+
step: StreamableStep<unknown>;
|
|
520
|
+
streamDetails: StreamDetails;
|
|
521
|
+
}
|
|
479
522
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Middleware } from "graphile-config";
|
|
2
|
+
declare const $$middleware: unique symbol;
|
|
3
|
+
export declare function getGrafastMiddleware(resolvedPreset: GraphileConfig.ResolvedPreset & {
|
|
4
|
+
[$$middleware]?: Middleware<GraphileConfig.GrafastMiddleware> | null;
|
|
5
|
+
}): Middleware<GraphileConfig.GrafastMiddleware> | null;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGrafastMiddleware = void 0;
|
|
4
|
+
const graphile_config_1 = require("graphile-config");
|
|
5
|
+
const $$middleware = Symbol("middleware");
|
|
6
|
+
function getGrafastMiddleware(resolvedPreset) {
|
|
7
|
+
if (resolvedPreset[$$middleware] !== undefined) {
|
|
8
|
+
return resolvedPreset[$$middleware];
|
|
9
|
+
}
|
|
10
|
+
let middleware = null;
|
|
11
|
+
(0, graphile_config_1.orderedApply)(resolvedPreset.plugins, (p) => p.grafast?.middleware, (name, fn, _plugin) => {
|
|
12
|
+
if (!middleware)
|
|
13
|
+
middleware = new graphile_config_1.Middleware();
|
|
14
|
+
middleware.register(name, fn);
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
resolvedPreset[$$middleware] = middleware;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Ignore - preset must be readonly
|
|
21
|
+
}
|
|
22
|
+
return middleware;
|
|
23
|
+
}
|
|
24
|
+
exports.getGrafastMiddleware = getGrafastMiddleware;
|
|
25
|
+
//# sourceMappingURL=middleware.js.map
|
package/dist/prepare.js
CHANGED
|
@@ -171,7 +171,7 @@ function outputBucket(outputPlan, rootBucket, rootBucketIndex, requestContext, p
|
|
|
171
171
|
releaseUnusedIterators(rootBucket, rootBucketIndex, ctx.root.streams);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function executePreemptive(operationPlan, variableValues, context, rootValue, outputDataAsString, executionTimeout) {
|
|
174
|
+
function executePreemptive(args, operationPlan, variableValues, context, rootValue, outputDataAsString, executionTimeout) {
|
|
175
175
|
const rootBucketIndex = 0;
|
|
176
176
|
const size = 1;
|
|
177
177
|
const polymorphicPathList = [OperationPlan_js_1.POLYMORPHIC_ROOT_PATH];
|
|
@@ -191,6 +191,7 @@ function executePreemptive(operationPlan, variableValues, context, rootValue, ou
|
|
|
191
191
|
const startTime = timeSource_js_1.timeSource.now();
|
|
192
192
|
const stopTime = executionTimeout !== null ? startTime + executionTimeout : null;
|
|
193
193
|
const requestContext = {
|
|
194
|
+
args,
|
|
194
195
|
startTime,
|
|
195
196
|
stopTime,
|
|
196
197
|
// toSerialize: [],
|
|
@@ -338,14 +339,17 @@ function executePreemptive(operationPlan, variableValues, context, rootValue, ou
|
|
|
338
339
|
return output();
|
|
339
340
|
}
|
|
340
341
|
}
|
|
342
|
+
function establishOperationPlanFromEvent(event) {
|
|
343
|
+
return (0, establishOperationPlan_js_1.establishOperationPlan)(event.schema, event.operation, event.fragments, event.variableValues, event.context, event.rootValue, event.planningTimeout);
|
|
344
|
+
}
|
|
341
345
|
/**
|
|
342
346
|
* @internal
|
|
343
347
|
*/
|
|
344
348
|
function grafastPrepare(args, options = {}) {
|
|
345
|
-
const { schema, contextValue: context, rootValue = Object.create(null),
|
|
349
|
+
const { schema, contextValue: context, rootValue = Object.create(null),
|
|
346
350
|
// operationName,
|
|
347
351
|
// document,
|
|
348
|
-
|
|
352
|
+
middleware, } = args;
|
|
349
353
|
const exeContext = (0, execute_1.buildExecutionContext)(args);
|
|
350
354
|
// If a list of errors was returned, abort
|
|
351
355
|
if (Array.isArray(exeContext) || "length" in exeContext) {
|
|
@@ -358,7 +362,21 @@ function grafastPrepare(args, options = {}) {
|
|
|
358
362
|
const planningTimeout = options.timeouts?.planning;
|
|
359
363
|
let operationPlan;
|
|
360
364
|
try {
|
|
361
|
-
|
|
365
|
+
if (middleware != null) {
|
|
366
|
+
operationPlan = middleware.runSync("establishOperationPlan", {
|
|
367
|
+
schema,
|
|
368
|
+
operation,
|
|
369
|
+
fragments,
|
|
370
|
+
variableValues,
|
|
371
|
+
context: context,
|
|
372
|
+
rootValue,
|
|
373
|
+
planningTimeout,
|
|
374
|
+
args,
|
|
375
|
+
}, establishOperationPlanFromEvent);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
operationPlan = (0, establishOperationPlan_js_1.establishOperationPlan)(schema, operation, fragments, variableValues, context, rootValue, planningTimeout);
|
|
379
|
+
}
|
|
362
380
|
}
|
|
363
381
|
catch (error) {
|
|
364
382
|
const graphqlError = error instanceof GraphQLError
|
|
@@ -379,7 +397,7 @@ function grafastPrepare(args, options = {}) {
|
|
|
379
397
|
});
|
|
380
398
|
}
|
|
381
399
|
const executionTimeout = options.timeouts?.execution ?? null;
|
|
382
|
-
return executePreemptive(operationPlan, variableValues, context, rootValue, options.outputDataAsString ?? false, executionTimeout);
|
|
400
|
+
return executePreemptive(args, operationPlan, variableValues, context, rootValue, options.outputDataAsString ?? false, executionTimeout);
|
|
383
401
|
}
|
|
384
402
|
exports.grafastPrepare = grafastPrepare;
|
|
385
403
|
function newIterator(abort) {
|
package/dist/subscribe.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.subscribe = void 0;
|
|
4
|
-
const config_js_1 = require("./config.js");
|
|
5
4
|
const execute_js_1 = require("./execute.js");
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const middleware_js_1 = require("./middleware.js");
|
|
6
|
+
function subscribe(args, legacyResolvedPreset, legacyOutputDataAsString) {
|
|
7
|
+
// TODO: remove legacy compatibility
|
|
8
|
+
if (legacyResolvedPreset !== undefined) {
|
|
9
|
+
args.resolvedPreset = legacyResolvedPreset;
|
|
10
|
+
}
|
|
11
|
+
if (legacyOutputDataAsString !== undefined) {
|
|
12
|
+
args.outputDataAsString = legacyOutputDataAsString;
|
|
13
|
+
}
|
|
14
|
+
const { resolvedPreset } = args;
|
|
15
|
+
const middleware = args.middleware === undefined && resolvedPreset != null
|
|
16
|
+
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
|
|
17
|
+
: args.middleware ?? null;
|
|
18
|
+
if (args.middleware === undefined) {
|
|
19
|
+
args.middleware = middleware;
|
|
20
|
+
}
|
|
21
|
+
if (middleware !== null) {
|
|
22
|
+
return middleware.run("subscribe", { args }, subscribeMiddlewareCallback);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return (0, execute_js_1.withGrafastArgs)(args);
|
|
26
|
+
}
|
|
8
27
|
}
|
|
9
28
|
exports.subscribe = subscribe;
|
|
29
|
+
const subscribeMiddlewareCallback = (event) => (0, execute_js_1.withGrafastArgs)(event.args);
|
|
10
30
|
//# sourceMappingURL=subscribe.js.map
|
package/dist/utils.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare function isPromise<T>(t: T | Promise<T>): t is Promise<T>;
|
|
|
21
21
|
/**
|
|
22
22
|
* Is "thenable".
|
|
23
23
|
*/
|
|
24
|
-
export declare function isPromiseLike<T>(t: T | Promise<T> | PromiseLike<T>): t is PromiseLike<T>;
|
|
24
|
+
export declare function isPromiseLike<T>(t: T | Promise<T> | PromiseLike<T>): t is PromiseLike<T> | Promise<T>;
|
|
25
25
|
/**
|
|
26
26
|
* Is a promise that can be externally resolved.
|
|
27
27
|
*/
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.1.1-beta.
|
|
1
|
+
export declare const version = "0.1.1-beta.11";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grafast",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.11",
|
|
4
4
|
"description": "Cutting edge GraphQL planning and execution engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@envelop/core": "^5.0.0",
|
|
69
|
-
"graphile-config": "^0.0.1-beta.
|
|
69
|
+
"graphile-config": "^0.0.1-beta.9",
|
|
70
70
|
"graphql": "^16.1.0-experimental-stream-defer.6",
|
|
71
71
|
"tamedevil": "^0.0.0-beta.7"
|
|
72
72
|
},
|