@envelop/core 2.3.2-alpha-a0c2439.0 → 2.3.2-alpha-fd02291.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.
Files changed (3) hide show
  1. package/index.js +42 -26
  2. package/index.mjs +42 -26
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1092,6 +1092,7 @@ const useSchema = (schema) => {
1092
1092
  };
1093
1093
  };
1094
1094
  const VALIDATE_FN = Symbol('VALIDATE_FN');
1095
+ const VALIDATION_ERRORS = Symbol('VALIDATION_ERRORS');
1095
1096
  const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
1096
1097
  let schemaSet$;
1097
1098
  return {
@@ -1100,36 +1101,44 @@ const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
1100
1101
  if (isPromise(schema$)) {
1101
1102
  schemaSet$ = schema$.then(schemaObj => {
1102
1103
  setSchema(schemaObj);
1104
+ return schemaObj;
1103
1105
  });
1104
1106
  }
1105
1107
  else {
1106
1108
  setSchema(schema$);
1107
1109
  }
1108
1110
  },
1109
- onValidate({ validateFn, setValidationFn, extendContext }) {
1110
- if (schemaSet$) {
1111
+ onValidate({ validateFn, params, setValidationFn, extendContext }) {
1112
+ // If schemaSet promise is still ongoing
1113
+ if (schemaSet$ != null) {
1111
1114
  if (validateSchema) {
1112
1115
  extendContext({
1113
- [VALIDATE_FN]: validateFn,
1116
+ [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1114
1117
  });
1115
1118
  }
1116
1119
  setValidationFn(() => []);
1117
1120
  }
1118
1121
  },
1119
- onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1120
- if (schemaSet$) {
1121
- const validateFn = contextValue[VALIDATE_FN];
1122
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema, document);
1122
+ async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1123
+ // If schemaSet promise is still ongoing
1124
+ if (context[VALIDATE_FN]) {
1125
+ const validateFn = context[VALIDATE_FN];
1126
+ const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1123
1127
  if (errors === null || errors === void 0 ? void 0 : errors.length) {
1124
- setResultAndStopExecution({
1125
- errors,
1128
+ extendContext({
1129
+ [VALIDATION_ERRORS]: errors,
1126
1130
  });
1127
- }
1128
- else {
1129
- return schemaSet$;
1131
+ breakContextBuilding();
1130
1132
  }
1131
1133
  }
1132
- return undefined;
1134
+ },
1135
+ onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1136
+ // If validation errors are set in context
1137
+ if (contextValue[VALIDATION_ERRORS]) {
1138
+ setResultAndStopExecution({
1139
+ errors: contextValue[VALIDATION_ERRORS],
1140
+ });
1141
+ }
1133
1142
  },
1134
1143
  };
1135
1144
  };
@@ -1140,36 +1149,43 @@ const useAsyncSchema = (schema$, validateSchema = true) => {
1140
1149
  if (isPromise(schema$)) {
1141
1150
  schemaSet$ = schema$.then(schemaObj => {
1142
1151
  setSchema(schemaObj);
1152
+ return schemaObj;
1143
1153
  });
1144
1154
  }
1145
1155
  else {
1146
1156
  setSchema(schema$);
1147
1157
  }
1148
1158
  },
1149
- onValidate({ validateFn, setValidationFn, extendContext }) {
1150
- if (schemaSet$) {
1159
+ onValidate({ validateFn, params, setValidationFn, extendContext }) {
1160
+ if (schemaSet$ != null) {
1151
1161
  if (validateSchema) {
1152
1162
  extendContext({
1153
- [VALIDATE_FN]: validateFn,
1163
+ [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1154
1164
  });
1155
1165
  }
1156
1166
  setValidationFn(() => []);
1157
1167
  }
1158
1168
  },
1159
- onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1160
- if (schemaSet$) {
1161
- const validateFn = contextValue[VALIDATE_FN];
1162
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema, document);
1169
+ async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1170
+ // If schemaSet promise is still ongoing
1171
+ if (context[VALIDATE_FN]) {
1172
+ const validateFn = context[VALIDATE_FN];
1173
+ const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1163
1174
  if (errors === null || errors === void 0 ? void 0 : errors.length) {
1164
- setResultAndStopExecution({
1165
- errors,
1175
+ extendContext({
1176
+ [VALIDATION_ERRORS]: errors,
1166
1177
  });
1167
- }
1168
- else {
1169
- return schemaSet$;
1178
+ breakContextBuilding();
1170
1179
  }
1171
1180
  }
1172
- return undefined;
1181
+ },
1182
+ onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1183
+ // If validation errors are set in context
1184
+ if (contextValue[VALIDATION_ERRORS]) {
1185
+ setResultAndStopExecution({
1186
+ errors: contextValue[VALIDATION_ERRORS],
1187
+ });
1188
+ }
1173
1189
  },
1174
1190
  };
1175
1191
  };
package/index.mjs CHANGED
@@ -1088,6 +1088,7 @@ const useSchema = (schema) => {
1088
1088
  };
1089
1089
  };
1090
1090
  const VALIDATE_FN = Symbol('VALIDATE_FN');
1091
+ const VALIDATION_ERRORS = Symbol('VALIDATION_ERRORS');
1091
1092
  const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
1092
1093
  let schemaSet$;
1093
1094
  return {
@@ -1096,36 +1097,44 @@ const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
1096
1097
  if (isPromise(schema$)) {
1097
1098
  schemaSet$ = schema$.then(schemaObj => {
1098
1099
  setSchema(schemaObj);
1100
+ return schemaObj;
1099
1101
  });
1100
1102
  }
1101
1103
  else {
1102
1104
  setSchema(schema$);
1103
1105
  }
1104
1106
  },
1105
- onValidate({ validateFn, setValidationFn, extendContext }) {
1106
- if (schemaSet$) {
1107
+ onValidate({ validateFn, params, setValidationFn, extendContext }) {
1108
+ // If schemaSet promise is still ongoing
1109
+ if (schemaSet$ != null) {
1107
1110
  if (validateSchema) {
1108
1111
  extendContext({
1109
- [VALIDATE_FN]: validateFn,
1112
+ [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1110
1113
  });
1111
1114
  }
1112
1115
  setValidationFn(() => []);
1113
1116
  }
1114
1117
  },
1115
- onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1116
- if (schemaSet$) {
1117
- const validateFn = contextValue[VALIDATE_FN];
1118
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema, document);
1118
+ async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1119
+ // If schemaSet promise is still ongoing
1120
+ if (context[VALIDATE_FN]) {
1121
+ const validateFn = context[VALIDATE_FN];
1122
+ const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1119
1123
  if (errors === null || errors === void 0 ? void 0 : errors.length) {
1120
- setResultAndStopExecution({
1121
- errors,
1124
+ extendContext({
1125
+ [VALIDATION_ERRORS]: errors,
1122
1126
  });
1123
- }
1124
- else {
1125
- return schemaSet$;
1127
+ breakContextBuilding();
1126
1128
  }
1127
1129
  }
1128
- return undefined;
1130
+ },
1131
+ onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1132
+ // If validation errors are set in context
1133
+ if (contextValue[VALIDATION_ERRORS]) {
1134
+ setResultAndStopExecution({
1135
+ errors: contextValue[VALIDATION_ERRORS],
1136
+ });
1137
+ }
1129
1138
  },
1130
1139
  };
1131
1140
  };
@@ -1136,36 +1145,43 @@ const useAsyncSchema = (schema$, validateSchema = true) => {
1136
1145
  if (isPromise(schema$)) {
1137
1146
  schemaSet$ = schema$.then(schemaObj => {
1138
1147
  setSchema(schemaObj);
1148
+ return schemaObj;
1139
1149
  });
1140
1150
  }
1141
1151
  else {
1142
1152
  setSchema(schema$);
1143
1153
  }
1144
1154
  },
1145
- onValidate({ validateFn, setValidationFn, extendContext }) {
1146
- if (schemaSet$) {
1155
+ onValidate({ validateFn, params, setValidationFn, extendContext }) {
1156
+ if (schemaSet$ != null) {
1147
1157
  if (validateSchema) {
1148
1158
  extendContext({
1149
- [VALIDATE_FN]: validateFn,
1159
+ [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1150
1160
  });
1151
1161
  }
1152
1162
  setValidationFn(() => []);
1153
1163
  }
1154
1164
  },
1155
- onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1156
- if (schemaSet$) {
1157
- const validateFn = contextValue[VALIDATE_FN];
1158
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema, document);
1165
+ async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1166
+ // If schemaSet promise is still ongoing
1167
+ if (context[VALIDATE_FN]) {
1168
+ const validateFn = context[VALIDATE_FN];
1169
+ const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1159
1170
  if (errors === null || errors === void 0 ? void 0 : errors.length) {
1160
- setResultAndStopExecution({
1161
- errors,
1171
+ extendContext({
1172
+ [VALIDATION_ERRORS]: errors,
1162
1173
  });
1163
- }
1164
- else {
1165
- return schemaSet$;
1174
+ breakContextBuilding();
1166
1175
  }
1167
1176
  }
1168
- return undefined;
1177
+ },
1178
+ onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1179
+ // If validation errors are set in context
1180
+ if (contextValue[VALIDATION_ERRORS]) {
1181
+ setResultAndStopExecution({
1182
+ errors: contextValue[VALIDATION_ERRORS],
1183
+ });
1184
+ }
1169
1185
  },
1170
1186
  };
1171
1187
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.3.2-alpha-a0c2439.0",
3
+ "version": "2.3.2-alpha-fd02291.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"