Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grafast

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grafast - npm Package Compare versions

Comparing version 0.1.1-beta.10 to 0.1.1-beta.11

dist/middleware.d.ts

11

dist/args.d.ts
import type { ExecutionArgs } from "graphql";
/**
* Applies Graphile Config hooks to your GraphQL request, e.g. to
* populate context or similar.
*
* @experimental
*/
export declare function hookArgs(rawArgs: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset, ctx: Partial<Grafast.RequestContext>): Grafast.ExecutionArgs | PromiseLike<Grafast.ExecutionArgs>;
import type { GrafastExecutionArgs, PromiseOrDirect } from "./interfaces.js";
/** @deprecated Pass `resolvedPreset` and `requestContext` via args directly */
export declare function hookArgs(rawArgs: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset, ctx: Partial<Grafast.RequestContext>): PromiseOrDirect<Grafast.ExecutionArgs>;
export declare function hookArgs(rawArgs: GrafastExecutionArgs): PromiseOrDirect<Grafast.ExecutionArgs>;
//# sourceMappingURL=args.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hookArgs = void 0;
const config_js_1 = require("./config.js");
const interfaces_js_1 = require("./interfaces.js");
const middleware_js_1 = require("./middleware.js");
const utils_js_1 = require("./utils.js");
const EMPTY_OBJECT = Object.freeze(Object.create(null));
/**

@@ -13,3 +14,18 @@ * Applies Graphile Config hooks to your GraphQL request, e.g. to

*/
function hookArgs(rawArgs, resolvedPreset, ctx) {
function hookArgs(rawArgs, legacyResolvedPreset, legacyCtx) {
if (legacyResolvedPreset !== undefined) {
rawArgs.resolvedPreset = legacyResolvedPreset;
}
if (legacyCtx !== undefined) {
rawArgs.requestContext = rawArgs.requestContext ?? legacyCtx;
}
const { middleware: rawMiddleware, resolvedPreset, contextValue: rawContextValue, } = rawArgs;
// Make context mutable
rawArgs.contextValue = Object.assign(Object.create(null), rawContextValue);
const middleware = rawMiddleware === undefined && resolvedPreset != null
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
: rawMiddleware ?? null;
if (rawMiddleware === undefined) {
rawArgs.middleware = middleware;
}
const args = rawArgs;

@@ -21,44 +37,38 @@ // Assert that args haven't already been hooked

args[interfaces_js_1.$$hooked] = true;
// Make context mutable
args.contextValue = Object.assign(Object.create(null), args.contextValue);
// finalize(args): args is deliberately shadowed
const finalize = (args) => {
const userContext = resolvedPreset.grafast?.context;
if (typeof userContext === "function") {
const result = userContext(ctx, args);
if ((0, utils_js_1.isPromiseLike)(result)) {
// Deliberately shadowed 'result'
return result.then((result) => {
Object.assign(args.contextValue, result);
return args;
});
}
else {
Object.assign(args.contextValue, result);
if (middleware != null) {
return middleware.run("prepareArgs", { args }, finalizeWithEvent);
}
else {
return finalize(args);
}
}
exports.hookArgs = hookArgs;
function finalize(args) {
const userContext = args.resolvedPreset?.grafast?.context;
const contextValue = args.contextValue;
if (typeof userContext === "function") {
const result = userContext(args.requestContext ?? EMPTY_OBJECT, args);
if ((0, utils_js_1.isPromiseLike)(result)) {
// Deliberately shadowed 'result'
return result.then((result) => {
Object.assign(contextValue, result);
return args;
}
});
}
else if (typeof userContext === "object" && userContext !== null) {
Object.assign(args.contextValue, userContext);
return args;
}
else {
Object.assign(contextValue, result);
return args;
}
};
if (resolvedPreset !== config_js_1.NULL_PRESET &&
resolvedPreset.plugins &&
resolvedPreset.plugins.length > 0) {
const event = { args, ctx, resolvedPreset };
const result = (0, config_js_1.hook)(resolvedPreset, "args", event);
if ((0, utils_js_1.isPromiseLike)(result)) {
return result.then(() => finalize(event.args));
}
else {
return finalize(event.args);
}
}
return finalize(args);
else if (typeof userContext === "object" && userContext !== null) {
Object.assign(contextValue, userContext);
return args;
}
else {
return args;
}
}
exports.hookArgs = hookArgs;
function finalizeWithEvent(event) {
return finalize(event.args);
}
//# sourceMappingURL=args.js.map

@@ -1,19 +0,2 @@

import type { AsyncHooks, PluginHook } from "graphile-config";
export declare const NULL_PRESET: GraphileConfig.ResolvedPreset;
type GraphileConfigModule = typeof import("graphile-config");
type PromiseOrValue<T> = T | Promise<T>;
export declare function withGraphileConfig<T>(callback: (graphileConfig: GraphileConfigModule | null) => PromiseOrValue<T>): PromiseOrValue<T>;
declare const $$skipHooks: unique symbol;
declare const $$hooksForPreset: unique symbol;
declare global {
namespace GraphileConfig {
interface ResolvedPreset {
[$$hooksForPreset]?: null | AsyncHooks<GraphileConfig.GrafastHooks>;
[$$skipHooks]?: Record<string, boolean>;
}
}
}
export declare function withHooks<TResult>(resolvedPreset: GraphileConfig.ResolvedPreset, callback: (hooks: AsyncHooks<GraphileConfig.GrafastHooks> | null) => PromiseOrValue<TResult>): PromiseOrValue<TResult>;
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>;
export {};
//# sourceMappingURL=config.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hook = exports.withHooks = exports.withGraphileConfig = exports.NULL_PRESET = void 0;
exports.NULL_PRESET = void 0;
exports.NULL_PRESET = Object.freeze(Object.create(null));
let graphileConfig = undefined;
let graphileConfigLoaded = false;
function withGraphileConfig(callback) {
if (graphileConfig === undefined) {
// ESM:
// This should be
// graphileConfig = import("graphile-config").then(
// but that causes a segfault in jest/node when testing third party
// modules. So we had to convert everything to CommonJS.
graphileConfig = new Promise((resolve, reject) => {
try {
resolve(require("graphile-config"));
}
catch (e) {
if (e.code === "ERR_REQUIRE_ESM") {
return import("graphile-config").then(resolve, reject);
}
else {
reject(e);
}
}
}).then((GC) => {
graphileConfig = GC;
graphileConfigLoaded = true;
return GC;
}, () => {
graphileConfig = null;
graphileConfigLoaded = true;
return null;
});
}
if (graphileConfigLoaded) {
return callback(graphileConfig);
}
else {
return graphileConfig.then(callback);
}
}
exports.withGraphileConfig = withGraphileConfig;
const $$skipHooks = Symbol("skipHooks");
const $$hooksForPreset = Symbol("grafastHooks");
function withHooks(resolvedPreset, callback) {
const existing = resolvedPreset[$$hooksForPreset];
if (existing !== undefined) {
return callback(existing);
}
if (!resolvedPreset.plugins || resolvedPreset.plugins.length === 0) {
resolvedPreset[$$hooksForPreset] = null;
return callback(null);
}
const plugins = resolvedPreset.plugins;
return withGraphileConfig((gc) => {
if (gc !== null) {
const hooks = new gc.AsyncHooks();
gc.applyHooks(plugins, (p) => p.grafast?.hooks, (name, fn, _plugin) => {
hooks.hook(name, fn);
});
resolvedPreset[$$hooksForPreset] = hooks;
return callback(hooks);
}
else {
resolvedPreset[$$hooksForPreset] = null;
return callback(null);
}
});
}
exports.withHooks = withHooks;
function hook(resolvedPreset, hookName, ...args) {
if (resolvedPreset[$$skipHooks]?.[hookName]) {
return;
}
return withHooks(resolvedPreset, (hooks) => {
if (hooks !== null) {
if (hooks.callbacks[hookName] !== undefined) {
return hooks.process(hookName, ...args);
}
else {
if (!resolvedPreset[$$skipHooks]) {
resolvedPreset[$$skipHooks] = Object.create(null);
}
resolvedPreset[$$skipHooks][hookName] = true;
return;
}
}
else {
if (!resolvedPreset[$$skipHooks]) {
resolvedPreset[$$skipHooks] = Object.create(null);
}
resolvedPreset[$$skipHooks][hookName] = true;
return;
}
});
}
exports.hook = hook;
//# sourceMappingURL=config.js.map

@@ -22,7 +22,5 @@ "use strict";

}
else if (exports.isDev && !exports.isTest) {
console.warn(`Grafast is running in development mode due to \`${graphileEnv !== undefined
? `GRAPHILE_ENV=${graphileEnv}`
: `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.`);
else if (exports.isDev && !exports.isTest && typeof graphileEnv === "undefined") {
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.`);
}
//# sourceMappingURL=dev.js.map

@@ -65,3 +65,4 @@ "use strict";

}
const { stopTime, eventEmitter } = requestContext;
const { stopTime, eventEmitter, args } = requestContext;
const { middleware } = args;
const { metaByMetaKey, size, store, layerPlan: { phases, children: childLayerPlans }, } = bucket;

@@ -578,3 +579,3 @@ const phaseCount = phases.length;

}
return step.stream({
const streamDetails = {
indexMap: makeIndexMap(count),

@@ -586,3 +587,9 @@ indexForEach: makeIndexForEach(count),

streamOptions,
});
};
if (!step.isSyncAndSafe && middleware != null) {
return middleware.run("streamStep", { args, step, streamDetails }, streamStepFromEvent);
}
else {
return step.stream(streamDetails);
}
}

@@ -593,3 +600,3 @@ else {

}
return step.execute({
const executeDetails = {
indexMap: makeIndexMap(count),

@@ -600,3 +607,9 @@ indexForEach: makeIndexForEach(count),

extra,
});
};
if (!step.isSyncAndSafe && middleware != null) {
return middleware.run("executeStep", { args, step, executeDetails }, executeStepFromEvent);
}
else {
return step.execute(executeDetails);
}
}

@@ -1088,2 +1101,8 @@ }

}
function streamStepFromEvent(event) {
return event.step.stream(event.streamDetails);
}
function executeStepFromEvent(event) {
return event.step.execute(event.executeDetails);
}
//# sourceMappingURL=executeBucket.js.map

@@ -8,3 +8,3 @@ import type { AsyncExecutionResult, ExecutionArgs, ExecutionResult } from "graphql";

*/
export declare function execute(args: GrafastExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset | undefined, outputDataAsString?: boolean): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
export declare function execute(args: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset | undefined, outputDataAsString?: boolean): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
/**

@@ -14,3 +14,3 @@ * Use this instead of GraphQL.js' execute method and we'll automatically

*/
export declare function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
export declare function execute(args: GrafastExecutionArgs): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
//# sourceMappingURL=execute.d.ts.map

@@ -6,6 +6,6 @@ "use strict";

const eventemitter3_1 = tslib_1.__importDefault(require("eventemitter3"));
const config_js_1 = require("./config.js");
const dev_js_1 = require("./dev.js");
const inspect_js_1 = require("./inspect.js");
const interfaces_js_1 = require("./interfaces.js");
const middleware_js_1 = require("./middleware.js");
const prepare_js_1 = require("./prepare.js");

@@ -17,4 +17,4 @@ const utils_js_1 = require("./utils.js");

*/
function withGrafastArgs(args, resolvedPreset, outputDataAsString) {
const options = resolvedPreset?.grafast;
function withGrafastArgs(args) {
const options = args.resolvedPreset?.grafast;
if (dev_js_1.isDev) {

@@ -59,4 +59,5 @@ if (args.rootValue != null &&

explain: options?.explain,
outputDataAsString,
timeouts: options?.timeouts,
// TODO: Delete this
outputDataAsString: args.outputDataAsString,
});

@@ -75,6 +76,26 @@ if (unlisten !== null) {

exports.withGrafastArgs = withGrafastArgs;
function execute(args, resolvedPreset, outputDataAsString) {
return withGrafastArgs(args, args.resolvedPreset ?? resolvedPreset ?? config_js_1.NULL_PRESET, args.outputDataAsString ?? outputDataAsString ?? false);
function execute(args, legacyResolvedPreset, legacyOutputDataAsString) {
// TODO: remove legacy compatibility
if (legacyResolvedPreset !== undefined) {
args.resolvedPreset = legacyResolvedPreset;
}
if (legacyOutputDataAsString !== undefined) {
args.outputDataAsString = legacyOutputDataAsString;
}
const { resolvedPreset } = args;
const middleware = args.middleware === undefined && resolvedPreset != null
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
: args.middleware ?? null;
if (args.middleware === undefined) {
args.middleware = middleware;
}
if (middleware !== null) {
return middleware.run("execute", { args }, executeMiddlewareCallback);
}
else {
return withGrafastArgs(args);
}
}
exports.execute = execute;
const executeMiddlewareCallback = (event) => withGrafastArgs(event.args);
//# sourceMappingURL=execute.js.map

@@ -5,7 +5,12 @@ import type { AsyncExecutionResult, ExecutionResult } from "graphql";

/**
* @deprecated Second and third parameters should be passed as part of args,
* specifically `resolvedPreset` and `requestContext`.
*/
export declare function grafast(args: GrafastArgs, legacyResolvedPreset?: GraphileConfig.ResolvedPreset, legacyCtx?: Partial<Grafast.RequestContext>): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
/**
* A replacement for GraphQL.js' `graphql` method that calls Grafast's
* execute instead
*/
export declare function grafast(args: GrafastArgs, legacyResolvedPreset?: GraphileConfig.ResolvedPreset, legacyCtx?: Partial<Grafast.RequestContext>): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
export declare function grafast(args: GrafastArgs): PromiseOrValue<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, undefined>>;
export declare function grafastSync(args: GrafastArgs, legacyResolvedPreset?: GraphileConfig.ResolvedPreset, legacyRequestContext?: Partial<Grafast.RequestContext>): ExecutionResult;
//# sourceMappingURL=grafastGraphql.d.ts.map

@@ -11,2 +11,3 @@ "use strict";

const interfaces_js_1 = require("./interfaces.js");
const middleware_js_1 = require("./middleware.js");
const utils_js_1 = require("./utils.js");

@@ -83,10 +84,20 @@ const { GraphQLError, parse, Source, validate, validateSchema } = graphql;

};
/**
* A replacement for GraphQL.js' `graphql` method that calls Grafast's
* execute instead
*/
function grafast(args, legacyResolvedPreset, legacyCtx) {
const { schema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver, resolvedPreset = legacyResolvedPreset, requestContext = legacyCtx, } = args;
// Convert legacy args to properties on `args`:
if (legacyResolvedPreset !== undefined) {
args.resolvedPreset = args.resolvedPreset ?? legacyResolvedPreset;
}
if (legacyCtx !== undefined) {
args.requestContext = args.requestContext ?? legacyCtx;
}
const { schema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver, resolvedPreset, requestContext, middleware: rawMiddleware, } = args;
const middleware = rawMiddleware !== undefined
? rawMiddleware
: resolvedPreset != null
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
: null;
// Validate Schema
const schemaValidationErrors = validateSchema(schema);
const schemaValidationErrors = middleware != null && resolvedPreset != null
? middleware.runSync("validateSchema", { schema, resolvedPreset }, validateSchemaWithEvent)
: validateSchema(schema);
if (schemaValidationErrors.length > 0) {

@@ -96,3 +107,5 @@ return { errors: schemaValidationErrors };

// Cached parse and validate
const documentOrErrors = parseAndValidate(schema, source);
const documentOrErrors = middleware != null && resolvedPreset != null
? middleware.runSync("parseAndValidate", { resolvedPreset, schema, source }, parseAndValidateWithEvent)
: parseAndValidate(schema, source);
if (Array.isArray(documentOrErrors)) {

@@ -111,16 +124,17 @@ return { errors: documentOrErrors };

typeResolver,
middleware,
resolvedPreset,
requestContext,
};
if (resolvedPreset && requestContext) {
const argsOrPromise = (0, index_js_1.hookArgs)(executionArgs, resolvedPreset, requestContext);
const argsOrPromise = (0, index_js_1.hookArgs)(executionArgs);
if ((0, utils_js_1.isPromiseLike)(argsOrPromise)) {
return Promise.resolve(argsOrPromise).then((hookedArgs) => (0, execute_js_1.execute)(hookedArgs, resolvedPreset));
return Promise.resolve(argsOrPromise).then(execute_js_1.execute);
}
else {
// Execute
return (0, execute_js_1.execute)(argsOrPromise, resolvedPreset);
return (0, execute_js_1.execute)(argsOrPromise);
}
}
else {
// Execute
return (0, execute_js_1.execute)(executionArgs, resolvedPreset);
return (0, execute_js_1.execute)(executionArgs);
}

@@ -137,2 +151,8 @@ }

exports.grafastSync = grafastSync;
function validateSchemaWithEvent(event) {
return validateSchema(event.schema);
}
function parseAndValidateWithEvent(event) {
return parseAndValidate(event.schema, event.source);
}
//# sourceMappingURL=grafastGraphql.js.map
import "./thereCanBeOnlyOne.js";
import type LRU from "@graphile/lru";
import type { PluginHook } from "graphile-config";
import type { DocumentNode, ExecutionArgs as GraphQLExecutionArgs, GraphQLError, OperationDefinitionNode } from "graphql";
import type { CallbackOrDescriptor, MiddlewareNext } from "graphile-config";
import type { DocumentNode, GraphQLError, OperationDefinitionNode } from "graphql";
import type { DataFromObjectSteps } from "./steps/object.js";

@@ -17,4 +17,5 @@ type PromiseOrValue<T> = T | Promise<T>;

import { grafast, grafastSync } from "./grafastGraphql.js";
import type { $$cacheByOperation, $$hooked, $$queryCache, CacheByOperationEntry, DataFromStep, GrafastExecutionArgs, GrafastTimeouts, ScalarInputPlanResolver } from "./interfaces.js";
import type { $$cacheByOperation, $$hooked, $$queryCache, CacheByOperationEntry, DataFromStep, EstablishOperationPlanEvent, ExecuteEvent, ExecuteStepEvent, GrafastExecutionArgs, GrafastTimeouts, ParseAndValidateEvent, PrepareArgsEvent, ScalarInputPlanResolver, StreamStepEvent, ValidateSchemaEvent } from "./interfaces.js";
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";
import { getGrafastMiddleware } from "./middleware.js";
import { polymorphicWrap } from "./polymorphic.js";

@@ -28,3 +29,3 @@ import { assertExecutableStep, assertListCapableStep, assertModifierStep, BaseStep, ExecutableStep, isExecutableStep, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isStreamableStep, ListCapableStep, ListLikeStep, ModifierStep, ObjectLikeStep, PolymorphicStep, StreamableStep, UnbatchedExecutableStep } from "./step.js";

export { isAsyncIterable } from "iterall";
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, };
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, };
export { hookArgs } from "./args.js";

@@ -38,3 +39,3 @@ export { version } from "./version.js";

namespace Grafast {
type ExecutionArgs = Pick<GraphQLExecutionArgs, "schema" | "document" | "rootValue" | "variableValues" | "operationName"> & {
type ExecutionArgs = Pick<GrafastExecutionArgs, "schema" | "document" | "rootValue" | "variableValues" | "operationName" | "resolvedPreset" | "middleware" | "requestContext" | "outputDataAsString"> & {
[$$hooked]?: boolean;

@@ -148,12 +149,20 @@ contextValue: Grafast.Context;

}
interface GrafastHooks {
args: PluginHook<(event: {
args: Grafast.ExecutionArgs;
ctx: Grafast.RequestContext;
resolvedPreset: GraphileConfig.ResolvedPreset;
}) => PromiseOrValue<void>>;
interface GrafastMiddleware {
/** Synchronous! */
validateSchema(event: ValidateSchemaEvent): readonly GraphQLError[];
/** Synchronous! */
parseAndValidate(event: ParseAndValidateEvent): DocumentNode | readonly GraphQLError[];
prepareArgs(event: PrepareArgsEvent): PromiseOrDirect<Grafast.ExecutionArgs>;
execute(event: ExecuteEvent): ReturnType<typeof execute>;
subscribe(event: ExecuteEvent): ReturnType<typeof subscribe>;
/** Synchronous! */
establishOperationPlan(event: EstablishOperationPlanEvent): OperationPlan;
executeStep(event: ExecuteStepEvent): PromiseOrDirect<GrafastResultsList<any>>;
streamStep(event: StreamStepEvent): PromiseOrDirect<GrafastResultStreamList<unknown>>;
}
interface Plugin {
grafast?: {
hooks?: GrafastHooks;
middleware?: {
[key in keyof GrafastMiddleware]?: CallbackOrDescriptor<GrafastMiddleware[key] extends (...args: infer UArgs) => infer UResult ? (next: MiddlewareNext<Awaited<UResult>>, ...args: UArgs) => UResult : never>;
};
};

@@ -160,0 +169,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
exports.objectSpec = 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 = void 0;
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;
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;
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;
const tslib_1 = require("tslib");

@@ -46,2 +46,4 @@ require("./thereCanBeOnlyOne.js");

Object.defineProperty(exports, "$$verbatim", { enumerable: true, get: function () { return interfaces_js_1.$$verbatim; } });
const middleware_js_1 = require("./middleware.js");
Object.defineProperty(exports, "getGrafastMiddleware", { enumerable: true, get: function () { return middleware_js_1.getGrafastMiddleware; } });
const polymorphic_js_1 = require("./polymorphic.js");

@@ -174,2 +176,3 @@ Object.defineProperty(exports, "polymorphicWrap", { enumerable: true, get: function () { return polymorphic_js_1.polymorphicWrap; } });

execute: execute_js_1.execute,
getGrafastMiddleware: middleware_js_1.getGrafastMiddleware,
grafast: grafastGraphql_js_1.grafast,

@@ -176,0 +179,0 @@ grafastSync: grafastGraphql_js_1.grafastSync,

import type EventEmitter from "eventemitter3";
import type { ASTNode, ExecutionArgs, FragmentDefinitionNode, GraphQLArgs, GraphQLArgument, GraphQLArgumentConfig, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLList, GraphQLNonNull, GraphQLOutputType, GraphQLScalarType, GraphQLSchema, GraphQLType, ValueNode, VariableNode } from "graphql";
import type { Middleware } from "graphile-config";
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";
import type { ObjMap } from "graphql/jsutils/ObjMap.js";
import type { OperationPlan } from "./engine/OperationPlan.js";
import type { FlaggedValue, SafeError } from "./error.js";
import type { ExecutableStep, ListCapableStep, ModifierStep } from "./step.js";
import type { ExecutableStep, ListCapableStep, ModifierStep, StreamableStep } from "./step.js";
import type { __InputDynamicScalarStep } from "./steps/__inputDynamicScalar.js";

@@ -464,2 +466,3 @@ import type { __InputListStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __TrackedValueStep, __TrackedValueStepWithDollars, ConstantStep } from "./steps/index.js";

requestContext?: Partial<Grafast.RequestContext>;
middleware?: Middleware<GraphileConfig.GrafastMiddleware> | null;
}

@@ -478,4 +481,44 @@ export type Maybe<T> = T | null | undefined;

resolvedPreset?: GraphileConfig.ResolvedPreset;
middleware?: Middleware<GraphileConfig.GrafastMiddleware> | null;
requestContext?: Partial<Grafast.RequestContext>;
outputDataAsString?: boolean;
}
export interface ValidateSchemaEvent {
resolvedPreset: GraphileConfig.ResolvedPreset;
schema: GraphQLSchema;
}
export interface ParseAndValidateEvent {
resolvedPreset: GraphileConfig.ResolvedPreset;
schema: GraphQLSchema;
source: string | Source;
}
export interface PrepareArgsEvent {
args: Grafast.ExecutionArgs;
}
export interface ExecuteEvent {
args: GrafastExecutionArgs;
}
export interface SubscribeEvent {
args: GrafastExecutionArgs;
}
export interface EstablishOperationPlanEvent {
schema: GraphQLSchema;
operation: OperationDefinitionNode;
fragments: ObjMap<FragmentDefinitionNode>;
variableValues: Record<string, any>;
context: any;
rootValue: any;
planningTimeout: number | undefined;
args: GrafastExecutionArgs;
}
export interface ExecuteStepEvent {
args: GrafastExecutionArgs;
step: ExecutableStep;
executeDetails: ExecutionDetails;
}
export interface StreamStepEvent {
args: GrafastExecutionArgs;
step: StreamableStep<unknown>;
streamDetails: StreamDetails;
}
//# sourceMappingURL=interfaces.d.ts.map

@@ -174,3 +174,3 @@ "use strict";

}
function executePreemptive(operationPlan, variableValues, context, rootValue, outputDataAsString, executionTimeout) {
function executePreemptive(args, operationPlan, variableValues, context, rootValue, outputDataAsString, executionTimeout) {
const rootBucketIndex = 0;

@@ -195,2 +195,3 @@ const size = 1;

const requestContext = {
args,
startTime,

@@ -343,2 +344,5 @@ stopTime,

}
function establishOperationPlanFromEvent(event) {
return (0, establishOperationPlan_js_1.establishOperationPlan)(event.schema, event.operation, event.fragments, event.variableValues, event.context, event.rootValue, event.planningTimeout);
}
/**

@@ -348,6 +352,6 @@ * @internal

function grafastPrepare(args, options = {}) {
const { schema, contextValue: context, rootValue = Object.create(null),
const { schema, contextValue: context, rootValue = Object.create(null),
// operationName,
// document,
} = args;
middleware, } = args;
const exeContext = (0, execute_1.buildExecutionContext)(args);

@@ -365,3 +369,17 @@ // If a list of errors was returned, abort

try {
operationPlan = (0, establishOperationPlan_js_1.establishOperationPlan)(schema, operation, fragments, variableValues, context, rootValue, planningTimeout);
if (middleware != null) {
operationPlan = middleware.runSync("establishOperationPlan", {
schema,
operation,
fragments,
variableValues,
context: context,
rootValue,
planningTimeout,
args,
}, establishOperationPlanFromEvent);
}
else {
operationPlan = (0, establishOperationPlan_js_1.establishOperationPlan)(schema, operation, fragments, variableValues, context, rootValue, planningTimeout);
}
}

@@ -387,3 +405,3 @@ catch (error) {

const executionTimeout = options.timeouts?.execution ?? null;
return executePreemptive(operationPlan, variableValues, context, rootValue, options.outputDataAsString ?? false, executionTimeout);
return executePreemptive(args, operationPlan, variableValues, context, rootValue, options.outputDataAsString ?? false, executionTimeout);
}

@@ -390,0 +408,0 @@ exports.grafastPrepare = grafastPrepare;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.subscribe = void 0;
const config_js_1 = require("./config.js");
const execute_js_1 = require("./execute.js");
function subscribe(args, resolvedPreset, outputDataAsString) {
return (0, execute_js_1.withGrafastArgs)(args, args.resolvedPreset ?? resolvedPreset ?? config_js_1.NULL_PRESET, args.outputDataAsString ?? outputDataAsString ?? false);
const middleware_js_1 = require("./middleware.js");
function subscribe(args, legacyResolvedPreset, legacyOutputDataAsString) {
// TODO: remove legacy compatibility
if (legacyResolvedPreset !== undefined) {
args.resolvedPreset = legacyResolvedPreset;
}
if (legacyOutputDataAsString !== undefined) {
args.outputDataAsString = legacyOutputDataAsString;
}
const { resolvedPreset } = args;
const middleware = args.middleware === undefined && resolvedPreset != null
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
: args.middleware ?? null;
if (args.middleware === undefined) {
args.middleware = middleware;
}
if (middleware !== null) {
return middleware.run("subscribe", { args }, subscribeMiddlewareCallback);
}
else {
return (0, execute_js_1.withGrafastArgs)(args);
}
}
exports.subscribe = subscribe;
const subscribeMiddlewareCallback = (event) => (0, execute_js_1.withGrafastArgs)(event.args);
//# sourceMappingURL=subscribe.js.map

@@ -24,3 +24,3 @@ import type { ConstValueNode, FieldNode, GraphQLEnumValueConfig, GraphQLFieldConfig, GraphQLInputFieldConfig, GraphQLInputObjectTypeConfig, GraphQLInputType, GraphQLNamedType, GraphQLObjectTypeConfig, GraphQLOutputType, GraphQLSchema } from "graphql";

*/
export declare function isPromiseLike<T>(t: T | Promise<T> | PromiseLike<T>): t is PromiseLike<T>;
export declare function isPromiseLike<T>(t: T | Promise<T> | PromiseLike<T>): t is PromiseLike<T> | Promise<T>;
/**

@@ -27,0 +27,0 @@ * Is a promise that can be externally resolved.

@@ -1,2 +0,2 @@

export declare const version = "0.1.1-beta.10";
export declare const version = "0.1.1-beta.11";
//# sourceMappingURL=version.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

// This file is autogenerated by /scripts/postversion.mjs
exports.version = "0.1.1-beta.10";
exports.version = "0.1.1-beta.11";
//# sourceMappingURL=version.js.map
{
"name": "grafast",
"version": "0.1.1-beta.10",
"version": "0.1.1-beta.11",
"description": "Cutting edge GraphQL planning and execution engine",

@@ -69,3 +69,3 @@ "main": "dist/index.js",

"@envelop/core": "^5.0.0",
"graphile-config": "^0.0.1-beta.8",
"graphile-config": "^0.0.1-beta.9",
"graphql": "^16.1.0-experimental-stream-defer.6",

@@ -72,0 +72,0 @@ "tamedevil": "^0.0.0-beta.7"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc