@envelop/core 2.3.2-alpha-c913692.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 +6 -95
- package/index.mjs +7 -95
- 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,103 +1087,19 @@ 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
|
-
schemaSet$ = undefined;
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
else {
|
|
1108
|
-
setSchema(schema$);
|
|
1109
|
-
}
|
|
1110
|
-
},
|
|
1111
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1112
|
-
if (schemaSet$) {
|
|
1113
|
-
if (validateSchema) {
|
|
1114
|
-
extendContext({
|
|
1115
|
-
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
setValidationFn(() => []);
|
|
1119
|
-
}
|
|
1120
|
-
},
|
|
1121
|
-
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1122
|
-
if (context[VALIDATE_FN]) {
|
|
1123
|
-
const schema = await schemaSet$;
|
|
1124
|
-
const validateFn = context[VALIDATE_FN];
|
|
1125
|
-
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1126
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1127
|
-
extendContext({
|
|
1128
|
-
[VALIDATION_ERRORS]: errors,
|
|
1129
|
-
});
|
|
1130
|
-
breakContextBuilding();
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
},
|
|
1134
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1135
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1136
|
-
setResultAndStopExecution({
|
|
1137
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1093
|
+
setSchema(schemaLoader(context));
|
|
1140
1094
|
},
|
|
1141
1095
|
};
|
|
1142
1096
|
};
|
|
1143
|
-
const useAsyncSchema = (
|
|
1144
|
-
let schemaSet$;
|
|
1097
|
+
const useAsyncSchema = (schemaPromise) => {
|
|
1145
1098
|
return {
|
|
1146
1099
|
onPluginInit({ setSchema }) {
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
// Once the schema is completely resolved, we don't need to keep the logic below.
|
|
1151
|
-
schemaSet$ = undefined;
|
|
1152
|
-
return schemaObj;
|
|
1153
|
-
});
|
|
1154
|
-
}
|
|
1155
|
-
else {
|
|
1156
|
-
setSchema(schema$);
|
|
1157
|
-
}
|
|
1158
|
-
},
|
|
1159
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1160
|
-
// If schemaSet promise is still ongoing
|
|
1161
|
-
if (schemaSet$) {
|
|
1162
|
-
if (validateSchema) {
|
|
1163
|
-
extendContext({
|
|
1164
|
-
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
setValidationFn(() => []);
|
|
1168
|
-
}
|
|
1169
|
-
},
|
|
1170
|
-
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1171
|
-
// If schemaSet promise is still ongoing
|
|
1172
|
-
if (schemaSet$) {
|
|
1173
|
-
const schema = await schemaSet$;
|
|
1174
|
-
const validateFn = context[VALIDATE_FN];
|
|
1175
|
-
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1176
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1177
|
-
extendContext({
|
|
1178
|
-
[VALIDATION_ERRORS]: errors,
|
|
1179
|
-
});
|
|
1180
|
-
breakContextBuilding();
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
},
|
|
1184
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1185
|
-
// If validation errors are set in context
|
|
1186
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1187
|
-
setResultAndStopExecution({
|
|
1188
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1189
|
-
});
|
|
1190
|
-
}
|
|
1100
|
+
schemaPromise.then(schemaObj => {
|
|
1101
|
+
setSchema(schemaObj);
|
|
1102
|
+
});
|
|
1191
1103
|
},
|
|
1192
1104
|
};
|
|
1193
1105
|
};
|
|
@@ -1384,7 +1296,6 @@ exports.isIntrospectionOperation = isIntrospectionOperation;
|
|
|
1384
1296
|
exports.isIntrospectionOperationString = isIntrospectionOperationString;
|
|
1385
1297
|
exports.isOperationDefinition = isOperationDefinition;
|
|
1386
1298
|
exports.isPluginEnabled = isPluginEnabled;
|
|
1387
|
-
exports.isPromise = isPromise;
|
|
1388
1299
|
exports.makeExecute = makeExecute;
|
|
1389
1300
|
exports.makeSubscribe = makeSubscribe;
|
|
1390
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,103 +1083,19 @@ 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
|
-
schemaSet$ = undefined;
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
else {
|
|
1104
|
-
setSchema(schema$);
|
|
1105
|
-
}
|
|
1106
|
-
},
|
|
1107
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1108
|
-
if (schemaSet$) {
|
|
1109
|
-
if (validateSchema) {
|
|
1110
|
-
extendContext({
|
|
1111
|
-
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
setValidationFn(() => []);
|
|
1115
|
-
}
|
|
1116
|
-
},
|
|
1117
|
-
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1118
|
-
if (context[VALIDATE_FN]) {
|
|
1119
|
-
const schema = await schemaSet$;
|
|
1120
|
-
const validateFn = context[VALIDATE_FN];
|
|
1121
|
-
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1122
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1123
|
-
extendContext({
|
|
1124
|
-
[VALIDATION_ERRORS]: errors,
|
|
1125
|
-
});
|
|
1126
|
-
breakContextBuilding();
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
},
|
|
1130
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1131
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1132
|
-
setResultAndStopExecution({
|
|
1133
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1089
|
+
setSchema(schemaLoader(context));
|
|
1136
1090
|
},
|
|
1137
1091
|
};
|
|
1138
1092
|
};
|
|
1139
|
-
const useAsyncSchema = (
|
|
1140
|
-
let schemaSet$;
|
|
1093
|
+
const useAsyncSchema = (schemaPromise) => {
|
|
1141
1094
|
return {
|
|
1142
1095
|
onPluginInit({ setSchema }) {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
// Once the schema is completely resolved, we don't need to keep the logic below.
|
|
1147
|
-
schemaSet$ = undefined;
|
|
1148
|
-
return schemaObj;
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
-
setSchema(schema$);
|
|
1153
|
-
}
|
|
1154
|
-
},
|
|
1155
|
-
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1156
|
-
// If schemaSet promise is still ongoing
|
|
1157
|
-
if (schemaSet$) {
|
|
1158
|
-
if (validateSchema) {
|
|
1159
|
-
extendContext({
|
|
1160
|
-
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
setValidationFn(() => []);
|
|
1164
|
-
}
|
|
1165
|
-
},
|
|
1166
|
-
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1167
|
-
// If schemaSet promise is still ongoing
|
|
1168
|
-
if (schemaSet$) {
|
|
1169
|
-
const schema = await schemaSet$;
|
|
1170
|
-
const validateFn = context[VALIDATE_FN];
|
|
1171
|
-
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1172
|
-
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1173
|
-
extendContext({
|
|
1174
|
-
[VALIDATION_ERRORS]: errors,
|
|
1175
|
-
});
|
|
1176
|
-
breakContextBuilding();
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
},
|
|
1180
|
-
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1181
|
-
// If validation errors are set in context
|
|
1182
|
-
if (contextValue[VALIDATION_ERRORS]) {
|
|
1183
|
-
setResultAndStopExecution({
|
|
1184
|
-
errors: contextValue[VALIDATION_ERRORS],
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1096
|
+
schemaPromise.then(schemaObj => {
|
|
1097
|
+
setSchema(schemaObj);
|
|
1098
|
+
});
|
|
1187
1099
|
},
|
|
1188
1100
|
};
|
|
1189
1101
|
};
|
|
@@ -1357,4 +1269,4 @@ const useImmediateIntrospection = () => {
|
|
|
1357
1269
|
};
|
|
1358
1270
|
};
|
|
1359
1271
|
|
|
1360
|
-
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>;
|