@envelop/core 2.1.0 → 2.2.0-alpha-555debe.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.
- package/index.js +30 -19
- package/index.mjs +30 -19
- package/package.json +1 -1
- package/plugins/use-error-handler.d.ts +2 -2
package/index.js
CHANGED
|
@@ -1099,22 +1099,33 @@ const useAsyncSchema = (schemaPromise) => {
|
|
|
1099
1099
|
};
|
|
1100
1100
|
};
|
|
1101
1101
|
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1102
|
+
const useErrorHandler = (errorHandler) => {
|
|
1103
|
+
return {
|
|
1104
|
+
onValidate({ context, params }) {
|
|
1105
|
+
return function ({ result }) {
|
|
1106
|
+
if (result.length) {
|
|
1107
|
+
errorHandler(result, {
|
|
1108
|
+
schema: params.schema,
|
|
1109
|
+
document: params.documentAST,
|
|
1110
|
+
contextValue: context,
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
},
|
|
1115
|
+
onExecute() {
|
|
1116
|
+
return {
|
|
1117
|
+
onExecuteDone(payload) {
|
|
1118
|
+
return handleStreamOrSingleExecutionResult(payload, ({ result, args }) => {
|
|
1119
|
+
var _a;
|
|
1120
|
+
if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1121
|
+
errorHandler(result.errors, args);
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
},
|
|
1125
|
+
};
|
|
1126
|
+
},
|
|
1127
|
+
};
|
|
1107
1128
|
};
|
|
1108
|
-
const useErrorHandler = (errorHandler) => ({
|
|
1109
|
-
onExecute() {
|
|
1110
|
-
const handleResult = makeHandleResult(errorHandler);
|
|
1111
|
-
return {
|
|
1112
|
-
onExecuteDone(payload) {
|
|
1113
|
-
return handleStreamOrSingleExecutionResult(payload, handleResult);
|
|
1114
|
-
},
|
|
1115
|
-
};
|
|
1116
|
-
},
|
|
1117
|
-
});
|
|
1118
1129
|
|
|
1119
1130
|
const useExtendContext = (contextFactory) => ({
|
|
1120
1131
|
async onContextBuilding({ context, extendContext }) {
|
|
@@ -1122,7 +1133,7 @@ const useExtendContext = (contextFactory) => ({
|
|
|
1122
1133
|
},
|
|
1123
1134
|
});
|
|
1124
1135
|
|
|
1125
|
-
const makeHandleResult
|
|
1136
|
+
const makeHandleResult = (formatter) => ({ args, result, setResult, }) => {
|
|
1126
1137
|
const modified = formatter(result, args);
|
|
1127
1138
|
if (modified !== false) {
|
|
1128
1139
|
setResult(modified);
|
|
@@ -1130,7 +1141,7 @@ const makeHandleResult$1 = (formatter) => ({ args, result, setResult, }) => {
|
|
|
1130
1141
|
};
|
|
1131
1142
|
const usePayloadFormatter = (formatter) => ({
|
|
1132
1143
|
onExecute() {
|
|
1133
|
-
const handleResult = makeHandleResult
|
|
1144
|
+
const handleResult = makeHandleResult(formatter);
|
|
1134
1145
|
return {
|
|
1135
1146
|
onExecuteDone(payload) {
|
|
1136
1147
|
return handleStreamOrSingleExecutionResult(payload, handleResult);
|
|
@@ -1161,7 +1172,7 @@ const formatError = (err, message, isDev) => {
|
|
|
1161
1172
|
}
|
|
1162
1173
|
return new graphql.GraphQLError(message);
|
|
1163
1174
|
};
|
|
1164
|
-
const makeHandleResult$
|
|
1175
|
+
const makeHandleResult$1 = (format, message, isDev) => ({ result, setResult }) => {
|
|
1165
1176
|
if (result.errors != null) {
|
|
1166
1177
|
setResult({ ...result, errors: result.errors.map(error => format(error, message, isDev)) });
|
|
1167
1178
|
}
|
|
@@ -1172,7 +1183,7 @@ const useMaskedErrors = (opts) => {
|
|
|
1172
1183
|
const message = (opts === null || opts === void 0 ? void 0 : opts.errorMessage) || DEFAULT_ERROR_MESSAGE;
|
|
1173
1184
|
// eslint-disable-next-line dot-notation
|
|
1174
1185
|
const isDev = (_b = opts === null || opts === void 0 ? void 0 : opts.isDev) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
|
|
1175
|
-
const handleResult = makeHandleResult$
|
|
1186
|
+
const handleResult = makeHandleResult$1(format, message, isDev);
|
|
1176
1187
|
return {
|
|
1177
1188
|
onPluginInit(context) {
|
|
1178
1189
|
context.registerContextErrorHandler(({ error, setError }) => {
|
package/index.mjs
CHANGED
|
@@ -1095,22 +1095,33 @@ const useAsyncSchema = (schemaPromise) => {
|
|
|
1095
1095
|
};
|
|
1096
1096
|
};
|
|
1097
1097
|
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1098
|
+
const useErrorHandler = (errorHandler) => {
|
|
1099
|
+
return {
|
|
1100
|
+
onValidate({ context, params }) {
|
|
1101
|
+
return function ({ result }) {
|
|
1102
|
+
if (result.length) {
|
|
1103
|
+
errorHandler(result, {
|
|
1104
|
+
schema: params.schema,
|
|
1105
|
+
document: params.documentAST,
|
|
1106
|
+
contextValue: context,
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
},
|
|
1111
|
+
onExecute() {
|
|
1112
|
+
return {
|
|
1113
|
+
onExecuteDone(payload) {
|
|
1114
|
+
return handleStreamOrSingleExecutionResult(payload, ({ result, args }) => {
|
|
1115
|
+
var _a;
|
|
1116
|
+
if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1117
|
+
errorHandler(result.errors, args);
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
},
|
|
1121
|
+
};
|
|
1122
|
+
},
|
|
1123
|
+
};
|
|
1103
1124
|
};
|
|
1104
|
-
const useErrorHandler = (errorHandler) => ({
|
|
1105
|
-
onExecute() {
|
|
1106
|
-
const handleResult = makeHandleResult(errorHandler);
|
|
1107
|
-
return {
|
|
1108
|
-
onExecuteDone(payload) {
|
|
1109
|
-
return handleStreamOrSingleExecutionResult(payload, handleResult);
|
|
1110
|
-
},
|
|
1111
|
-
};
|
|
1112
|
-
},
|
|
1113
|
-
});
|
|
1114
1125
|
|
|
1115
1126
|
const useExtendContext = (contextFactory) => ({
|
|
1116
1127
|
async onContextBuilding({ context, extendContext }) {
|
|
@@ -1118,7 +1129,7 @@ const useExtendContext = (contextFactory) => ({
|
|
|
1118
1129
|
},
|
|
1119
1130
|
});
|
|
1120
1131
|
|
|
1121
|
-
const makeHandleResult
|
|
1132
|
+
const makeHandleResult = (formatter) => ({ args, result, setResult, }) => {
|
|
1122
1133
|
const modified = formatter(result, args);
|
|
1123
1134
|
if (modified !== false) {
|
|
1124
1135
|
setResult(modified);
|
|
@@ -1126,7 +1137,7 @@ const makeHandleResult$1 = (formatter) => ({ args, result, setResult, }) => {
|
|
|
1126
1137
|
};
|
|
1127
1138
|
const usePayloadFormatter = (formatter) => ({
|
|
1128
1139
|
onExecute() {
|
|
1129
|
-
const handleResult = makeHandleResult
|
|
1140
|
+
const handleResult = makeHandleResult(formatter);
|
|
1130
1141
|
return {
|
|
1131
1142
|
onExecuteDone(payload) {
|
|
1132
1143
|
return handleStreamOrSingleExecutionResult(payload, handleResult);
|
|
@@ -1157,7 +1168,7 @@ const formatError = (err, message, isDev) => {
|
|
|
1157
1168
|
}
|
|
1158
1169
|
return new GraphQLError(message);
|
|
1159
1170
|
};
|
|
1160
|
-
const makeHandleResult$
|
|
1171
|
+
const makeHandleResult$1 = (format, message, isDev) => ({ result, setResult }) => {
|
|
1161
1172
|
if (result.errors != null) {
|
|
1162
1173
|
setResult({ ...result, errors: result.errors.map(error => format(error, message, isDev)) });
|
|
1163
1174
|
}
|
|
@@ -1168,7 +1179,7 @@ const useMaskedErrors = (opts) => {
|
|
|
1168
1179
|
const message = (opts === null || opts === void 0 ? void 0 : opts.errorMessage) || DEFAULT_ERROR_MESSAGE;
|
|
1169
1180
|
// eslint-disable-next-line dot-notation
|
|
1170
1181
|
const isDev = (_b = opts === null || opts === void 0 ? void 0 : opts.isDev) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
|
|
1171
|
-
const handleResult = makeHandleResult$
|
|
1182
|
+
const handleResult = makeHandleResult$1(format, message, isDev);
|
|
1172
1183
|
return {
|
|
1173
1184
|
onPluginInit(context) {
|
|
1174
1185
|
context.registerContextErrorHandler(({ error, setError }) => {
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin, DefaultContext } from '@envelop/types';
|
|
1
|
+
import { Plugin, DefaultContext, TypedExecutionArgs } from '@envelop/types';
|
|
2
2
|
import { GraphQLError } from 'graphql';
|
|
3
|
-
export declare type ErrorHandler = (errors: readonly GraphQLError[], context:
|
|
3
|
+
export declare type ErrorHandler = <TContext = DefaultContext>(errors: readonly GraphQLError[], context: TypedExecutionArgs<TContext>) => void;
|
|
4
4
|
export declare const useErrorHandler: <ContextType>(errorHandler: ErrorHandler) => Plugin<ContextType>;
|