@envelop/core 2.1.1-alpha-e859732.0 → 2.2.0-alpha-e0e4d8e.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 +29 -3
- package/index.mjs +29 -3
- package/package.json +2 -2
- package/plugins/use-error-handler.d.ts +1 -1
- package/plugins/use-extend-context.d.ts +1 -1
- package/plugins/use-masked-errors.d.ts +10 -0
- package/utils.d.ts +1 -1
package/index.js
CHANGED
|
@@ -475,6 +475,9 @@ function createEnvelopOrchestrator(plugins) {
|
|
|
475
475
|
extendContext: extension => {
|
|
476
476
|
Object.assign(context, extension);
|
|
477
477
|
},
|
|
478
|
+
setResult: newResult => {
|
|
479
|
+
result = newResult;
|
|
480
|
+
},
|
|
478
481
|
});
|
|
479
482
|
}
|
|
480
483
|
return result;
|
|
@@ -1146,13 +1149,18 @@ class EnvelopError extends graphql.GraphQLError {
|
|
|
1146
1149
|
}
|
|
1147
1150
|
}
|
|
1148
1151
|
const formatError = (err, message, isDev) => {
|
|
1152
|
+
var _a, _b, _c, _d;
|
|
1149
1153
|
if (err instanceof graphql.GraphQLError) {
|
|
1150
|
-
if (
|
|
1154
|
+
if (
|
|
1155
|
+
/** execution error */
|
|
1156
|
+
(err.originalError && err.originalError instanceof EnvelopError === false) ||
|
|
1157
|
+
/** validate and parse errors */
|
|
1158
|
+
(err.originalError === undefined && err instanceof EnvelopError === false)) {
|
|
1151
1159
|
return new graphql.GraphQLError(message, err.nodes, err.source, err.positions, err.path, undefined, isDev
|
|
1152
1160
|
? {
|
|
1153
1161
|
originalError: {
|
|
1154
|
-
message: err.originalError.message,
|
|
1155
|
-
stack: err.originalError.stack,
|
|
1162
|
+
message: (_b = (_a = err.originalError) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : err.message,
|
|
1163
|
+
stack: (_d = (_c = err.originalError) === null || _c === void 0 ? void 0 : _c.stack) !== null && _d !== void 0 ? _d : err.stack,
|
|
1156
1164
|
},
|
|
1157
1165
|
}
|
|
1158
1166
|
: undefined);
|
|
@@ -1174,6 +1182,24 @@ const useMaskedErrors = (opts) => {
|
|
|
1174
1182
|
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
1183
|
const handleResult = makeHandleResult$2(format, message, isDev);
|
|
1176
1184
|
return {
|
|
1185
|
+
onParse: (opts === null || opts === void 0 ? void 0 : opts.onParse) === true
|
|
1186
|
+
? function onParse() {
|
|
1187
|
+
return function onParseEnd({ result, replaceParseResult }) {
|
|
1188
|
+
if (result instanceof Error) {
|
|
1189
|
+
replaceParseResult(format(result, message, isDev));
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
: undefined,
|
|
1194
|
+
onValidate: (opts === null || opts === void 0 ? void 0 : opts.onValidate) === true
|
|
1195
|
+
? function onValidate() {
|
|
1196
|
+
return function onValidateEnd({ valid, result, setResult }) {
|
|
1197
|
+
if (valid === false) {
|
|
1198
|
+
setResult(result.map(error => format(error, message, isDev)));
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
: undefined,
|
|
1177
1203
|
onPluginInit(context) {
|
|
1178
1204
|
context.registerContextErrorHandler(({ error, setError }) => {
|
|
1179
1205
|
setError(formatError(error, message, isDev));
|
package/index.mjs
CHANGED
|
@@ -471,6 +471,9 @@ function createEnvelopOrchestrator(plugins) {
|
|
|
471
471
|
extendContext: extension => {
|
|
472
472
|
Object.assign(context, extension);
|
|
473
473
|
},
|
|
474
|
+
setResult: newResult => {
|
|
475
|
+
result = newResult;
|
|
476
|
+
},
|
|
474
477
|
});
|
|
475
478
|
}
|
|
476
479
|
return result;
|
|
@@ -1142,13 +1145,18 @@ class EnvelopError extends GraphQLError {
|
|
|
1142
1145
|
}
|
|
1143
1146
|
}
|
|
1144
1147
|
const formatError = (err, message, isDev) => {
|
|
1148
|
+
var _a, _b, _c, _d;
|
|
1145
1149
|
if (err instanceof GraphQLError) {
|
|
1146
|
-
if (
|
|
1150
|
+
if (
|
|
1151
|
+
/** execution error */
|
|
1152
|
+
(err.originalError && err.originalError instanceof EnvelopError === false) ||
|
|
1153
|
+
/** validate and parse errors */
|
|
1154
|
+
(err.originalError === undefined && err instanceof EnvelopError === false)) {
|
|
1147
1155
|
return new GraphQLError(message, err.nodes, err.source, err.positions, err.path, undefined, isDev
|
|
1148
1156
|
? {
|
|
1149
1157
|
originalError: {
|
|
1150
|
-
message: err.originalError.message,
|
|
1151
|
-
stack: err.originalError.stack,
|
|
1158
|
+
message: (_b = (_a = err.originalError) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : err.message,
|
|
1159
|
+
stack: (_d = (_c = err.originalError) === null || _c === void 0 ? void 0 : _c.stack) !== null && _d !== void 0 ? _d : err.stack,
|
|
1152
1160
|
},
|
|
1153
1161
|
}
|
|
1154
1162
|
: undefined);
|
|
@@ -1170,6 +1178,24 @@ const useMaskedErrors = (opts) => {
|
|
|
1170
1178
|
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
1179
|
const handleResult = makeHandleResult$2(format, message, isDev);
|
|
1172
1180
|
return {
|
|
1181
|
+
onParse: (opts === null || opts === void 0 ? void 0 : opts.onParse) === true
|
|
1182
|
+
? function onParse() {
|
|
1183
|
+
return function onParseEnd({ result, replaceParseResult }) {
|
|
1184
|
+
if (result instanceof Error) {
|
|
1185
|
+
replaceParseResult(format(result, message, isDev));
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
: undefined,
|
|
1190
|
+
onValidate: (opts === null || opts === void 0 ? void 0 : opts.onValidate) === true
|
|
1191
|
+
? function onValidate() {
|
|
1192
|
+
return function onValidateEnd({ valid, result, setResult }) {
|
|
1193
|
+
if (valid === false) {
|
|
1194
|
+
setResult(result.map(error => format(error, message, isDev)));
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
: undefined,
|
|
1173
1199
|
onPluginInit(context) {
|
|
1174
1200
|
context.registerContextErrorHandler(({ error, setError }) => {
|
|
1175
1201
|
setError(formatError(error, message, isDev));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha-e0e4d8e.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@envelop/types": "2.0
|
|
9
|
+
"@envelop/types": "2.1.0-alpha-e0e4d8e.0"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Plugin, DefaultContext } from '@envelop/types';
|
|
2
2
|
import { GraphQLError } from 'graphql';
|
|
3
3
|
export declare type ErrorHandler = (errors: readonly GraphQLError[], context: Readonly<DefaultContext>) => void;
|
|
4
|
-
export declare const useErrorHandler: <ContextType>(errorHandler: ErrorHandler) => Plugin<ContextType
|
|
4
|
+
export declare const useErrorHandler: <ContextType>(errorHandler: ErrorHandler) => Plugin<ContextType>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin } from '@envelop/types';
|
|
2
2
|
export declare type ContextFactoryFn<TResult = unknown, TCurrent = unknown> = (currentContext: TCurrent) => TResult | Promise<TResult>;
|
|
3
3
|
declare type UnwrapAsync<T> = T extends Promise<infer U> ? U : T;
|
|
4
|
-
export declare const useExtendContext: <TContextFactory extends (...args: any[]) => any>(contextFactory: TContextFactory) => Plugin<UnwrapAsync<ReturnType<TContextFactory
|
|
4
|
+
export declare const useExtendContext: <TContextFactory extends (...args: any[]) => any>(contextFactory: TContextFactory) => Plugin<UnwrapAsync<ReturnType<TContextFactory>>>;
|
|
5
5
|
export {};
|
|
@@ -16,5 +16,15 @@ export declare type UseMaskedErrorsOpts = {
|
|
|
16
16
|
* The default value is `process.env['NODE_ENV'] === 'development'`
|
|
17
17
|
*/
|
|
18
18
|
isDev?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether parse errors should be masked.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
onParse?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether validation errors should be masked.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
onValidate?: boolean;
|
|
19
29
|
};
|
|
20
30
|
export declare const useMaskedErrors: (opts?: UseMaskedErrorsOpts | undefined) => Plugin;
|
package/utils.d.ts
CHANGED
|
@@ -28,6 +28,6 @@ export declare function isAsyncIterable<TType>(maybeAsyncIterable: unknown): may
|
|
|
28
28
|
* @param fn The handler to be executed on each result
|
|
29
29
|
* @returns a subscription for streamed results, or undefined in case of an non-async
|
|
30
30
|
*/
|
|
31
|
-
export declare function handleStreamOrSingleExecutionResult<
|
|
31
|
+
export declare function handleStreamOrSingleExecutionResult<ContextType = DefaultContext>(payload: OnExecuteDoneEventPayload<ContextType>, fn: OnExecuteDoneHookResultOnNextHook<ContextType>): void | OnExecuteDoneHookResult<ContextType>;
|
|
32
32
|
export declare function finalAsyncIterator<TInput>(source: AsyncIterable<TInput>, onFinal: () => void): AsyncGenerator<TInput>;
|
|
33
33
|
export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>;
|