UNPKG

grafast

Version:

Cutting edge GraphQL planning and execution engine

57 lines 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withGlobalLayerPlan = withGlobalLayerPlan; exports.currentLayerPlan = currentLayerPlan; exports.currentPolymorphicPaths = currentPolymorphicPaths; exports.currentPlanningPath = currentPlanningPath; exports.isUnaryStep = isUnaryStep; const global_js_1 = require("../../global.js"); let globalData_layerPlan = undefined; let globalData_polymorphicPaths = undefined; let globalData_planningPath = undefined; function withGlobalLayerPlan(layerPlan, polymorphicPaths, planningPath, callback, callbackThis, ...callbackArgs) { const oldLayerPlan = globalData_layerPlan; globalData_layerPlan = layerPlan; const oldPolymorphicPaths = globalData_polymorphicPaths; globalData_polymorphicPaths = polymorphicPaths; const oldPlanningPath = globalData_planningPath; // Keep the old planning path if we've not been given a new one if (planningPath != null) { globalData_planningPath = planningPath; } try { return callback.apply(callbackThis, callbackArgs); } finally { globalData_layerPlan = oldLayerPlan; globalData_polymorphicPaths = oldPolymorphicPaths; globalData_planningPath = oldPlanningPath; } } function currentLayerPlan() { if (globalData_layerPlan === undefined) { throw new Error( // Must only be called from inside `withGlobalLayerPlan`! "Now is not a valid time to call `currentLayerPlan`. This error typically occurs when you attempt to call a Grafast step function from outside of the planning lifecycle - it's important to note that Grafast plans must be resolved synchronously, so check for 'async' or 'setTimeout' or any location where a step function is called outside of a plan resolver. For more information, read about plan resolvers: https://grafast.org/grafast/plan-resolvers"); } return globalData_layerPlan; } function currentPolymorphicPaths() { if (globalData_polymorphicPaths === undefined) { throw new Error("GrafastInternalError<b0b05743-8b21-42c6-9b53-925013d88bd1>: currentPolymorphicPaths called out of turn; must only called within a withGlobalLayerPlan callback"); } return globalData_polymorphicPaths; } /** UNUSED */ function currentPlanningPath() { const opPlan = (0, global_js_1.operationPlan)(); if (opPlan.phase === "plan" && globalData_planningPath === undefined) { // This might happen during deduplicate for example console.warn("GrafastInternalWarning<6a484dc3-a690-493c-b8b3-d6196bf2c290>: currentPlanningPath could not retrieve the current path even in 'plan' phase"); } return globalData_planningPath; } function isUnaryStep($step) { return $step._isUnary; } //# sourceMappingURL=withGlobalLayerPlan.js.map