@envelop/core 2.3.2-alpha-b81730b.0 → 2.3.2-alpha-763ffe6.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 +5 -87
- package/index.mjs +6 -87
- package/package.json +1 -1
- package/plugins/use-masked-errors.d.ts +2 -2
- package/plugins/use-schema.d.ts +3 -3
- package/utils.d.ts +0 -1
package/index.js
CHANGED
|
@@ -299,10 +299,6 @@ function errorAsyncIterator(source, onError) {
|
|
|
299
299
|
};
|
|
300
300
|
return stream;
|
|
301
301
|
}
|
|
302
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
303
|
-
function isPromise(obj) {
|
|
304
|
-
return obj != null && obj.then;
|
|
305
|
-
}
|
|
306
302
|
|
|
307
303
|
function createEnvelopOrchestrator(plugins) {
|
|
308
304
|
let schema = null;
|
|
@@ -1091,97 +1087,20 @@ const useSchema = (schema) => {
|
|
|
1091
1087
|
},
|
|
1092
1088
|
};
|
|
1093
1089
|
};
|
|
1094
|
-
const
|
|
1095
|
-
const VALIDATION_ERRORS = Symbol('VALIDATION_ERRORS');
|
|
1096
|
-
const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
|
|
1097
|
-
let schemaSet$;
|
|
1090
|
+
const useLazyLoadedSchema = (schemaLoader) => {
|
|
1098
1091
|
return {
|
|
1099
1092
|
onEnveloped({ setSchema, context }) {
|
|
1100
|
-
|
|
1101
|
-
if (isPromise(schema$)) {
|
|
1102
|
-
schemaSet$ = schema$.then(schemaObj => {
|
|
1103
|
-
setSchema(schemaObj);
|
|
1104
|
-
return schemaObj;
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
else {
|
|
1108
|
-
setSchema(schema$);
|
|
1109
|
-
}
|
|
1110
|
-
},
|
|
1111
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1112
|
-
if (schemaSet$ != null) {
|
|
1113
|
-
if (validateSchema) {
|
|
1114
|
-
extendContext({
|
|
1115
|
-
[VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
setValidationFn(() => []);
|
|
1119
|
-
}
|
|
1120
|
-
},
|
|
1121
|
-
onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1122
|
-
var _a;
|
|
1123
|
-
(_a = context[VALIDATE_FN]) === null || _a === void 0 ? void 0 : _a.call(context).then((errors) => {
|
|
1124
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1125
|
-
extendContext({
|
|
1126
|
-
[VALIDATION_ERRORS]: errors,
|
|
1127
|
-
});
|
|
1128
|
-
breakContextBuilding();
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
},
|
|
1132
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1133
|
-
// If validation errors are set in context
|
|
1134
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1135
|
-
setResultAndStopExecution({
|
|
1136
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1093
|
+
setSchema(schemaLoader(context));
|
|
1139
1094
|
},
|
|
1140
1095
|
};
|
|
1141
1096
|
};
|
|
1142
|
-
const useAsyncSchema = (
|
|
1143
|
-
let schemaSet$;
|
|
1097
|
+
const useAsyncSchema = (schemaPromise) => {
|
|
1144
1098
|
return {
|
|
1145
1099
|
onPluginInit({ setSchema }) {
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
setSchema(schemaObj);
|
|
1149
|
-
return schemaObj;
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
else {
|
|
1153
|
-
setSchema(schema$);
|
|
1154
|
-
}
|
|
1155
|
-
},
|
|
1156
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1157
|
-
if (schemaSet$ != null) {
|
|
1158
|
-
if (validateSchema) {
|
|
1159
|
-
extendContext({
|
|
1160
|
-
[VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
setValidationFn(() => []);
|
|
1164
|
-
}
|
|
1165
|
-
},
|
|
1166
|
-
onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1167
|
-
var _a;
|
|
1168
|
-
(_a = context[VALIDATE_FN]) === null || _a === void 0 ? void 0 : _a.call(context).then((errors) => {
|
|
1169
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1170
|
-
extendContext({
|
|
1171
|
-
[VALIDATION_ERRORS]: errors,
|
|
1172
|
-
});
|
|
1173
|
-
breakContextBuilding();
|
|
1174
|
-
}
|
|
1100
|
+
schemaPromise.then(schemaObj => {
|
|
1101
|
+
setSchema(schemaObj);
|
|
1175
1102
|
});
|
|
1176
1103
|
},
|
|
1177
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1178
|
-
// If validation errors are set in context
|
|
1179
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1180
|
-
setResultAndStopExecution({
|
|
1181
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
},
|
|
1185
1104
|
};
|
|
1186
1105
|
};
|
|
1187
1106
|
|
|
@@ -1377,7 +1296,6 @@ exports.isIntrospectionOperation = isIntrospectionOperation;
|
|
|
1377
1296
|
exports.isIntrospectionOperationString = isIntrospectionOperationString;
|
|
1378
1297
|
exports.isOperationDefinition = isOperationDefinition;
|
|
1379
1298
|
exports.isPluginEnabled = isPluginEnabled;
|
|
1380
|
-
exports.isPromise = isPromise;
|
|
1381
1299
|
exports.makeExecute = makeExecute;
|
|
1382
1300
|
exports.makeSubscribe = makeSubscribe;
|
|
1383
1301
|
exports.mapAsyncIterator = mapAsyncIterator;
|
package/index.mjs
CHANGED
|
@@ -295,10 +295,6 @@ function errorAsyncIterator(source, onError) {
|
|
|
295
295
|
};
|
|
296
296
|
return stream;
|
|
297
297
|
}
|
|
298
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
299
|
-
function isPromise(obj) {
|
|
300
|
-
return obj != null && obj.then;
|
|
301
|
-
}
|
|
302
298
|
|
|
303
299
|
function createEnvelopOrchestrator(plugins) {
|
|
304
300
|
let schema = null;
|
|
@@ -1087,97 +1083,20 @@ const useSchema = (schema) => {
|
|
|
1087
1083
|
},
|
|
1088
1084
|
};
|
|
1089
1085
|
};
|
|
1090
|
-
const
|
|
1091
|
-
const VALIDATION_ERRORS = Symbol('VALIDATION_ERRORS');
|
|
1092
|
-
const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
|
|
1093
|
-
let schemaSet$;
|
|
1086
|
+
const useLazyLoadedSchema = (schemaLoader) => {
|
|
1094
1087
|
return {
|
|
1095
1088
|
onEnveloped({ setSchema, context }) {
|
|
1096
|
-
|
|
1097
|
-
if (isPromise(schema$)) {
|
|
1098
|
-
schemaSet$ = schema$.then(schemaObj => {
|
|
1099
|
-
setSchema(schemaObj);
|
|
1100
|
-
return schemaObj;
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
else {
|
|
1104
|
-
setSchema(schema$);
|
|
1105
|
-
}
|
|
1106
|
-
},
|
|
1107
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1108
|
-
if (schemaSet$ != null) {
|
|
1109
|
-
if (validateSchema) {
|
|
1110
|
-
extendContext({
|
|
1111
|
-
[VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
setValidationFn(() => []);
|
|
1115
|
-
}
|
|
1116
|
-
},
|
|
1117
|
-
onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1118
|
-
var _a;
|
|
1119
|
-
(_a = context[VALIDATE_FN]) === null || _a === void 0 ? void 0 : _a.call(context).then((errors) => {
|
|
1120
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1121
|
-
extendContext({
|
|
1122
|
-
[VALIDATION_ERRORS]: errors,
|
|
1123
|
-
});
|
|
1124
|
-
breakContextBuilding();
|
|
1125
|
-
}
|
|
1126
|
-
});
|
|
1127
|
-
},
|
|
1128
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1129
|
-
// If validation errors are set in context
|
|
1130
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1131
|
-
setResultAndStopExecution({
|
|
1132
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1133
|
-
});
|
|
1134
|
-
}
|
|
1089
|
+
setSchema(schemaLoader(context));
|
|
1135
1090
|
},
|
|
1136
1091
|
};
|
|
1137
1092
|
};
|
|
1138
|
-
const useAsyncSchema = (
|
|
1139
|
-
let schemaSet$;
|
|
1093
|
+
const useAsyncSchema = (schemaPromise) => {
|
|
1140
1094
|
return {
|
|
1141
1095
|
onPluginInit({ setSchema }) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
setSchema(schemaObj);
|
|
1145
|
-
return schemaObj;
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
else {
|
|
1149
|
-
setSchema(schema$);
|
|
1150
|
-
}
|
|
1151
|
-
},
|
|
1152
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1153
|
-
if (schemaSet$ != null) {
|
|
1154
|
-
if (validateSchema) {
|
|
1155
|
-
extendContext({
|
|
1156
|
-
[VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
setValidationFn(() => []);
|
|
1160
|
-
}
|
|
1161
|
-
},
|
|
1162
|
-
onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1163
|
-
var _a;
|
|
1164
|
-
(_a = context[VALIDATE_FN]) === null || _a === void 0 ? void 0 : _a.call(context).then((errors) => {
|
|
1165
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1166
|
-
extendContext({
|
|
1167
|
-
[VALIDATION_ERRORS]: errors,
|
|
1168
|
-
});
|
|
1169
|
-
breakContextBuilding();
|
|
1170
|
-
}
|
|
1096
|
+
schemaPromise.then(schemaObj => {
|
|
1097
|
+
setSchema(schemaObj);
|
|
1171
1098
|
});
|
|
1172
1099
|
},
|
|
1173
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1174
|
-
// If validation errors are set in context
|
|
1175
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1176
|
-
setResultAndStopExecution({
|
|
1177
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
},
|
|
1181
1100
|
};
|
|
1182
1101
|
};
|
|
1183
1102
|
|
|
@@ -1350,4 +1269,4 @@ const useImmediateIntrospection = () => {
|
|
|
1350
1269
|
};
|
|
1351
1270
|
};
|
|
1352
1271
|
|
|
1353
|
-
export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled,
|
|
1272
|
+
export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from '@envelop/types';
|
|
2
|
-
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { GraphQLError, GraphQLErrorExtensions } from 'graphql';
|
|
3
3
|
export declare const DEFAULT_ERROR_MESSAGE = "Unexpected error.";
|
|
4
4
|
export declare class EnvelopError extends GraphQLError {
|
|
5
|
-
constructor(message: string, extensions?:
|
|
5
|
+
constructor(message: string, extensions?: GraphQLErrorExtensions);
|
|
6
6
|
}
|
|
7
7
|
export declare type FormatErrorHandler = (error: GraphQLError | unknown, message: string, isDev: boolean) => GraphQLError;
|
|
8
8
|
export declare const formatError: FormatErrorHandler;
|
package/plugins/use-schema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { DefaultContext, Maybe, Plugin
|
|
2
|
+
import { DefaultContext, Maybe, Plugin } from '@envelop/types';
|
|
3
3
|
export declare const useSchema: (schema: GraphQLSchema) => Plugin;
|
|
4
|
-
export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) =>
|
|
5
|
-
export declare const useAsyncSchema: (
|
|
4
|
+
export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => GraphQLSchema) => Plugin;
|
|
5
|
+
export declare const useAsyncSchema: (schemaPromise: Promise<GraphQLSchema>) => Plugin;
|
package/utils.d.ts
CHANGED
|
@@ -31,4 +31,3 @@ export declare function isAsyncIterable<TType>(maybeAsyncIterable: unknown): may
|
|
|
31
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>;
|
|
34
|
-
export declare function isPromise<T>(obj: any): obj is Promise<T>;
|