grafast 0.1.1-beta.12 → 0.1.1-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1118,6 +1118,7 @@ class OperationPlan {
1118
1118
  // PERF: this should be handled in the parent?
1119
1119
  const parentStep = this.stepTracker.getStepById(rawParentStep.id);
1120
1120
  const previousStepCount = this.stepTracker.stepCount;
1121
+ const previousSideEffectStep = layerPlan.latestSideEffectStep;
1121
1122
  if (this.loc !== null)
1122
1123
  this.loc.push(`planField(${path.join(".")})`);
1123
1124
  try {
@@ -1185,6 +1186,7 @@ class OperationPlan {
1185
1186
  }
1186
1187
  try {
1187
1188
  this.stepTracker.purgeBackTo(previousStepCount);
1189
+ layerPlan.latestSideEffectStep = previousSideEffectStep;
1188
1190
  }
1189
1191
  catch (e2) {
1190
1192
  console.error(`Cleanup error occurred whilst trying to recover from field planning error: ${e2.stack}`);
@@ -432,7 +432,7 @@ function executeBucket(bucket, requestContext) {
432
432
  }
433
433
  // End "f2b3b1b3" block
434
434
  }
435
- else {
435
+ else if (forceIndexValue === undefined) {
436
436
  const depVal = depExecutionVal.at(dataIndex);
437
437
  let depFlags;
438
438
  if ((bucket.flagUnion & interfaces_js_1.FLAG_ERROR) === interfaces_js_1.FLAG_ERROR &&
@@ -768,7 +768,7 @@ function executeBucket(bucket, requestContext) {
768
768
  }
769
769
  const result = needsFiltering
770
770
  ? reallyExecuteStepWithFiltering(step, dependencies, _rawForbiddenFlags, _rawOnReject, bucket.polymorphicPathList, extra)
771
- : reallyExecuteStepWithoutFiltering(step._isUnary ? 1 : size, step, dependencies, extra);
771
+ : reallyExecuteStepWithoutFiltering(step._isUnary ? 1 : size, step, $sideEffect ? dependencies.slice(0, depCount) : dependencies, extra);
772
772
  if ((0, utils_js_1.isPromiseLike)(result)) {
773
773
  return result.then(null, (error) => {
774
774
  // Don't need to do this here, it will be done where the
@@ -7,6 +7,11 @@ const constant_js_1 = require("./steps/constant.js");
7
7
  const list_js_1 = require("./steps/list.js");
8
8
  const object_js_1 = require("./steps/object.js");
9
9
  const { getNullableType, isEnumType, isInputObjectType, isListType, isScalarType, } = graphql;
10
+ function assertNotRuntime(operationPlan, description) {
11
+ if (operationPlan.phase === "ready") {
12
+ throw new Error(`${description} may only be called at planning time; however you have code that has attempted to call it during execution time. Please revisit your plan resolvers to locate the issue.`);
13
+ }
14
+ }
10
15
  function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAfterMode, callback) {
11
16
  if (operationPlan.loc !== null)
12
17
  operationPlan.loc.push(`withFieldArgsForArguments(${field.name})`);
@@ -20,6 +25,7 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
20
25
  let explicitlyApplied = false;
21
26
  const fieldArgs = {
22
27
  getRaw(path) {
28
+ assertNotRuntime(operationPlan, `fieldArgs.getRaw()`);
23
29
  if (typeof path === "string") {
24
30
  return $all.get(path);
25
31
  }
@@ -47,6 +53,7 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
47
53
  }
48
54
  },
49
55
  get(inPath) {
56
+ assertNotRuntime(operationPlan, `fieldArgs.get()`);
50
57
  const path = Array.isArray(inPath)
51
58
  ? inPath
52
59
  : inPath
@@ -136,6 +143,7 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
136
143
  }
137
144
  },
138
145
  apply(targetStepOrCallback, inPath) {
146
+ assertNotRuntime(operationPlan, `fieldArgs.apply()`);
139
147
  const path = Array.isArray(inPath) ? inPath : inPath ? [inPath] : [];
140
148
  const pathString = path.join(".");
141
149
  const $existing = applied.get(pathString);
@@ -243,9 +251,11 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
243
251
  const nullableEntityType = getNullableType(entityType);
244
252
  const localFieldArgs = {
245
253
  getRaw(subpath) {
254
+ assertNotRuntime(operationPlan, `fieldArgs.getRaw()`);
246
255
  return fieldArgs.getRaw(concatPath(path, subpath));
247
256
  },
248
257
  get(subpath) {
258
+ assertNotRuntime(operationPlan, `fieldArgs.get()`);
249
259
  if (!subpath || (Array.isArray(subpath) && subpath.length === 0)) {
250
260
  if (isListType(nullableEntityType)) {
251
261
  if (!("evalLength" in $input)) {
@@ -307,6 +317,7 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
307
317
  return fieldArgs.get(concatPath(path, subpath));
308
318
  },
309
319
  apply(targetStepOrCallback, subpath) {
320
+ assertNotRuntime(operationPlan, `fieldArgs.apply()`);
310
321
  if (mode === "apply" &&
311
322
  (!subpath || (Array.isArray(subpath) && subpath.length === 0))) {
312
323
  if (isInputObjectType(nullableEntityType)) {
package/dist/step.js CHANGED
@@ -110,23 +110,49 @@ class ExecutableStep extends BaseStep {
110
110
  this.implicitSideEffectStep = null;
111
111
  this.hasSideEffects ??= false;
112
112
  let hasSideEffects = false;
113
+ const stepTracker = this.layerPlan.operationPlan.stepTracker;
113
114
  Object.defineProperty(this, "hasSideEffects", {
114
115
  get() {
115
116
  return hasSideEffects;
116
117
  },
117
118
  set(value) {
118
- if (this.id ===
119
- this.layerPlan.operationPlan.stepTracker.stepCount - 1) {
119
+ /**
120
+ * If steps were created after this step, an this step doesn't depend
121
+ * on them, then it's no longer safe to change hasSideEffects.
122
+ */
123
+ let nonDependentSteps = null;
124
+ const maxStepId = stepTracker.stepCount - 1;
125
+ if (this.id === maxStepId) {
126
+ // All good - no more steps were created
127
+ }
128
+ else {
129
+ // If the step created them during initialization and is dependent on
130
+ // them, that's fine too.
131
+ for (let id = this.id + 1; id <= maxStepId; id++) {
132
+ const step = stepTracker.getStepById(id);
133
+ if ((0, utils_js_1.stepADependsOnStepB)(this, step))
134
+ continue;
135
+ if (nonDependentSteps === null) {
136
+ nonDependentSteps = [step];
137
+ }
138
+ else {
139
+ nonDependentSteps.push(step);
140
+ }
141
+ }
142
+ }
143
+ if (nonDependentSteps === null) {
120
144
  hasSideEffects = value;
121
145
  if (value === true) {
122
146
  this.layerPlan.latestSideEffectStep = this;
123
147
  }
124
148
  else if (value !== true && hasSideEffects === true) {
125
- throw new Error(`Cannot mark a step has having no side effects after having set it to have side effects.`);
149
+ throw new Error(`Cannot mark ${this} as having no side effects after having set it to have side effects.`);
126
150
  }
127
151
  }
128
152
  else {
129
- throw new Error("You must mark a step as having side effects immediately after creating it, before any other steps are created.");
153
+ throw new Error(`Attempted to mark ${this} as having side effects, but other non-dependent steps (${nonDependentSteps
154
+ .map(String)
155
+ .join(", ")}) have already been created.`);
130
156
  }
131
157
  },
132
158
  enumerable: true,
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "0.1.1-beta.12";
1
+ export declare const version = "0.1.1-beta.14";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // This file is autogenerated by /scripts/postversion.mjs
5
- exports.version = "0.1.1-beta.12";
5
+ exports.version = "0.1.1-beta.14";
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grafast",
3
- "version": "0.1.1-beta.12",
3
+ "version": "0.1.1-beta.14",
4
4
  "description": "Cutting edge GraphQL planning and execution engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -59,6 +59,7 @@
59
59
  "chalk": "^4.1.2",
60
60
  "debug": "^4.3.4",
61
61
  "eventemitter3": "^5.0.1",
62
+ "graphile-config": "^0.0.1-beta.9",
62
63
  "graphql": "^16.1.0-experimental-stream-defer.6",
63
64
  "iterall": "^1.3.0",
64
65
  "tamedevil": "^0.0.0-beta.7",
@@ -66,16 +67,12 @@
66
67
  },
67
68
  "peerDependencies": {
68
69
  "@envelop/core": "^5.0.0",
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
  },
73
73
  "peerDependenciesMeta": {
74
74
  "@envelop/core": {
75
75
  "optional": true
76
- },
77
- "graphile-config": {
78
- "optional": true
79
76
  }
80
77
  },
81
78
  "files": [