@envelop/core 2.3.2-alpha-e3ced2d.0 → 2.3.2-alpha-3ace273.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 +40 -7
  2. package/index.mjs +40 -7
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1091,6 +1091,7 @@ const useSchema = (schema) => {
1091
1091
  },
1092
1092
  };
1093
1093
  };
1094
+ const VALIDATE_FN = Symbol('VALIDATE_FN');
1094
1095
  const useLazyLoadedSchema = (schemaLoader) => {
1095
1096
  let schemaSet$;
1096
1097
  return {
@@ -1105,9 +1106,26 @@ const useLazyLoadedSchema = (schemaLoader) => {
1105
1106
  setSchema(schema$);
1106
1107
  }
1107
1108
  },
1108
- onExecute() {
1109
+ onValidate({ validateFn, setValidationFn, extendContext }) {
1110
+ if (schemaSet$) {
1111
+ extendContext({
1112
+ [VALIDATE_FN]: validateFn,
1113
+ });
1114
+ setValidationFn(() => []);
1115
+ }
1116
+ },
1117
+ onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1109
1118
  if (schemaSet$) {
1110
- return schemaSet$;
1119
+ const validateFn = contextValue[VALIDATE_FN];
1120
+ const errors = validateFn(schema, document);
1121
+ if (errors === null || errors === void 0 ? void 0 : errors.length) {
1122
+ setResultAndStopExecution({
1123
+ errors,
1124
+ });
1125
+ }
1126
+ else {
1127
+ return schemaSet$;
1128
+ }
1111
1129
  }
1112
1130
  return undefined;
1113
1131
  },
@@ -1126,13 +1144,28 @@ const useAsyncSchema = (schema$) => {
1126
1144
  setSchema(schema$);
1127
1145
  }
1128
1146
  },
1129
- onContextBuilding() {
1130
- return () => {
1131
- if (schemaSet$) {
1147
+ onValidate({ validateFn, setValidationFn, extendContext }) {
1148
+ if (schemaSet$) {
1149
+ extendContext({
1150
+ [VALIDATE_FN]: validateFn,
1151
+ });
1152
+ setValidationFn(() => []);
1153
+ }
1154
+ },
1155
+ onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1156
+ if (schemaSet$) {
1157
+ const validateFn = contextValue[VALIDATE_FN];
1158
+ const errors = validateFn(schema, document);
1159
+ if (errors === null || errors === void 0 ? void 0 : errors.length) {
1160
+ setResultAndStopExecution({
1161
+ errors,
1162
+ });
1163
+ }
1164
+ else {
1132
1165
  return schemaSet$;
1133
1166
  }
1134
- return undefined;
1135
- };
1167
+ }
1168
+ return undefined;
1136
1169
  },
1137
1170
  };
1138
1171
  };
package/index.mjs CHANGED
@@ -1087,6 +1087,7 @@ const useSchema = (schema) => {
1087
1087
  },
1088
1088
  };
1089
1089
  };
1090
+ const VALIDATE_FN = Symbol('VALIDATE_FN');
1090
1091
  const useLazyLoadedSchema = (schemaLoader) => {
1091
1092
  let schemaSet$;
1092
1093
  return {
@@ -1101,9 +1102,26 @@ const useLazyLoadedSchema = (schemaLoader) => {
1101
1102
  setSchema(schema$);
1102
1103
  }
1103
1104
  },
1104
- onExecute() {
1105
+ onValidate({ validateFn, setValidationFn, extendContext }) {
1106
+ if (schemaSet$) {
1107
+ extendContext({
1108
+ [VALIDATE_FN]: validateFn,
1109
+ });
1110
+ setValidationFn(() => []);
1111
+ }
1112
+ },
1113
+ onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1105
1114
  if (schemaSet$) {
1106
- return schemaSet$;
1115
+ const validateFn = contextValue[VALIDATE_FN];
1116
+ const errors = validateFn(schema, document);
1117
+ if (errors === null || errors === void 0 ? void 0 : errors.length) {
1118
+ setResultAndStopExecution({
1119
+ errors,
1120
+ });
1121
+ }
1122
+ else {
1123
+ return schemaSet$;
1124
+ }
1107
1125
  }
1108
1126
  return undefined;
1109
1127
  },
@@ -1122,13 +1140,28 @@ const useAsyncSchema = (schema$) => {
1122
1140
  setSchema(schema$);
1123
1141
  }
1124
1142
  },
1125
- onContextBuilding() {
1126
- return () => {
1127
- if (schemaSet$) {
1143
+ onValidate({ validateFn, setValidationFn, extendContext }) {
1144
+ if (schemaSet$) {
1145
+ extendContext({
1146
+ [VALIDATE_FN]: validateFn,
1147
+ });
1148
+ setValidationFn(() => []);
1149
+ }
1150
+ },
1151
+ onExecute({ args: { schema, document, contextValue }, setResultAndStopExecution }) {
1152
+ if (schemaSet$) {
1153
+ const validateFn = contextValue[VALIDATE_FN];
1154
+ const errors = validateFn(schema, document);
1155
+ if (errors === null || errors === void 0 ? void 0 : errors.length) {
1156
+ setResultAndStopExecution({
1157
+ errors,
1158
+ });
1159
+ }
1160
+ else {
1128
1161
  return schemaSet$;
1129
1162
  }
1130
- return undefined;
1131
- };
1163
+ }
1164
+ return undefined;
1132
1165
  },
1133
1166
  };
1134
1167
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.3.2-alpha-e3ced2d.0",
3
+ "version": "2.3.2-alpha-3ace273.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"