@graphitation/supermassive 4.1.0 → 4.2.0

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.
@@ -20,7 +20,8 @@ import { promiseReduce } from "./jsutils/promiseReduce.mjs";
20
20
  import {
21
21
  getArgumentValues,
22
22
  getVariableValues,
23
- getDirectiveValues
23
+ getDirectiveValues,
24
+ getMissingVariableTypes
24
25
  } from "./values.mjs";
25
26
  import { arraysAreEqual } from "./utilities/array.mjs";
26
27
  import { isAsyncIterable } from "./jsutils/isAsyncIterable.mjs";
@@ -40,12 +41,26 @@ var collectSubfields = memoize3(
40
41
  (exeContext, returnTypeName, fieldGroup) => _collectSubfields(exeContext, returnTypeName.name, fieldGroup)
41
42
  );
42
43
  function executeWithoutSchema(args) {
44
+ const { document, variableValues } = args;
45
+ assertValidExecutionArguments(document, variableValues);
43
46
  const exeContext = buildExecutionContext(args);
44
- if (!("schemaFragment" in exeContext)) {
47
+ if (Array.isArray(exeContext)) {
45
48
  return { errors: exeContext };
46
- } else {
49
+ }
50
+ const coersionResult = populateVariableValuesInContext(
51
+ exeContext,
52
+ variableValues
53
+ );
54
+ const handleCoersionResult = (coersionErrors) => {
55
+ if (Array.isArray(coersionErrors)) {
56
+ return { errors: coersionErrors };
57
+ }
47
58
  return executeOperationWithBeforeHook(exeContext);
59
+ };
60
+ if (isPromise(coersionResult)) {
61
+ return coersionResult.then(handleCoersionResult);
48
62
  }
63
+ return handleCoersionResult(coersionResult);
49
64
  }
50
65
  function assertValidExecutionArguments(document, rawVariableValues) {
51
66
  devAssert(document, "Must provide document.");
@@ -54,8 +69,39 @@ function assertValidExecutionArguments(document, rawVariableValues) {
54
69
  "Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided."
55
70
  );
56
71
  }
72
+ function populateVariableValuesInContext(exeContext, rawVariableValues) {
73
+ var _a;
74
+ const { operation, schemaFragment } = exeContext;
75
+ const variableDefinitions = (_a = operation.variableDefinitions) != null ? _a : [];
76
+ const missingTypes = getMissingVariableTypes(
77
+ variableDefinitions,
78
+ schemaFragment
79
+ );
80
+ const coerce = () => {
81
+ const coercedVariableValues = getVariableValues(
82
+ schemaFragment,
83
+ variableDefinitions,
84
+ rawVariableValues != null ? rawVariableValues : {},
85
+ { maxErrors: 50 }
86
+ );
87
+ if (coercedVariableValues.errors) {
88
+ return coercedVariableValues.errors;
89
+ }
90
+ exeContext.variableValues = coercedVariableValues.coerced;
91
+ };
92
+ if (missingTypes.length) {
93
+ const pendingSchemaLoad = requestSchemaFragment(exeContext, {
94
+ kind: "InputVariables",
95
+ typeNames: missingTypes
96
+ });
97
+ if (isPromise(pendingSchemaLoad)) {
98
+ return pendingSchemaLoad.then(coerce);
99
+ }
100
+ }
101
+ return coerce();
102
+ }
57
103
  function buildExecutionContext(args) {
58
- var _a, _b;
104
+ var _a;
59
105
  const {
60
106
  schemaFragment,
61
107
  schemaFragmentLoader,
@@ -63,7 +109,6 @@ function buildExecutionContext(args) {
63
109
  rootValue,
64
110
  contextValue,
65
111
  buildContextValue,
66
- variableValues,
67
112
  operationName,
68
113
  fieldResolver,
69
114
  typeResolver,
@@ -72,7 +117,6 @@ function buildExecutionContext(args) {
72
117
  enablePerEventContext,
73
118
  enableEarlyExecution
74
119
  } = args;
75
- assertValidExecutionArguments(document, variableValues);
76
120
  let operation;
77
121
  const fragments = /* @__PURE__ */ Object.create(null);
78
122
  for (const definition of document.definitions) {
@@ -103,16 +147,6 @@ function buildExecutionContext(args) {
103
147
  }
104
148
  return [locatedError("Must provide an operation.", [])];
105
149
  }
106
- const variableDefinitions = (_b = operation.variableDefinitions) != null ? _b : [];
107
- const coercedVariableValues = getVariableValues(
108
- schemaFragment,
109
- variableDefinitions,
110
- variableValues != null ? variableValues : {},
111
- { maxErrors: 50 }
112
- );
113
- if (coercedVariableValues.errors) {
114
- return coercedVariableValues.errors;
115
- }
116
150
  return {
117
151
  schemaFragment,
118
152
  schemaFragmentLoader,
@@ -121,7 +155,7 @@ function buildExecutionContext(args) {
121
155
  contextValue: buildContextValue ? buildContextValue(contextValue) : contextValue,
122
156
  buildContextValue,
123
157
  operation,
124
- variableValues: coercedVariableValues.coerced,
158
+ variableValues: {},
125
159
  fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
126
160
  typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
127
161
  subscribeFieldResolver: subscribeFieldResolver != null ? subscribeFieldResolver : defaultFieldResolver,
@@ -2110,12 +2144,12 @@ function isTotalExecutionResult(result) {
2110
2144
  return !("initialResult" in result);
2111
2145
  }
2112
2146
  export {
2113
- assertValidExecutionArguments,
2114
2147
  buildResolveInfo,
2115
2148
  defaultFieldResolver,
2116
2149
  defaultTypeResolver,
2117
2150
  executeWithoutSchema,
2118
2151
  getOperationRootTypeName,
2119
2152
  isIncrementalExecutionResult,
2120
- isTotalExecutionResult
2153
+ isTotalExecutionResult,
2154
+ requestSchemaFragment
2121
2155
  };