@envelop/core 2.3.2-alpha-fd02291.0 → 2.3.2

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 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,101 +1087,19 @@ const useSchema = (schema) => {
1091
1087
  },
1092
1088
  };
1093
1089
  };
1094
- const VALIDATE_FN = Symbol('VALIDATE_FN');
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
- const schema$ = schemaLoader(context);
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 promise is still ongoing
1113
- if (schemaSet$ != null) {
1114
- if (validateSchema) {
1115
- extendContext({
1116
- [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1117
- });
1118
- }
1119
- setValidationFn(() => []);
1120
- }
1121
- },
1122
- async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1123
- // If schemaSet promise is still ongoing
1124
- if (context[VALIDATE_FN]) {
1125
- const validateFn = context[VALIDATE_FN];
1126
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1127
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
1128
- extendContext({
1129
- [VALIDATION_ERRORS]: errors,
1130
- });
1131
- breakContextBuilding();
1132
- }
1133
- }
1134
- },
1135
- onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1136
- // If validation errors are set in context
1137
- if (contextValue[VALIDATION_ERRORS]) {
1138
- setResultAndStopExecution({
1139
- errors: contextValue[VALIDATION_ERRORS],
1140
- });
1141
- }
1093
+ setSchema(schemaLoader(context));
1142
1094
  },
1143
1095
  };
1144
1096
  };
1145
- const useAsyncSchema = (schema$, validateSchema = true) => {
1146
- let schemaSet$;
1097
+ const useAsyncSchema = (schemaPromise) => {
1147
1098
  return {
1148
1099
  onPluginInit({ setSchema }) {
1149
- if (isPromise(schema$)) {
1150
- schemaSet$ = schema$.then(schemaObj => {
1151
- setSchema(schemaObj);
1152
- return schemaObj;
1153
- });
1154
- }
1155
- else {
1156
- setSchema(schema$);
1157
- }
1158
- },
1159
- onValidate({ validateFn, params, setValidationFn, extendContext }) {
1160
- if (schemaSet$ != null) {
1161
- if (validateSchema) {
1162
- extendContext({
1163
- [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1164
- });
1165
- }
1166
- setValidationFn(() => []);
1167
- }
1168
- },
1169
- async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1170
- // If schemaSet promise is still ongoing
1171
- if (context[VALIDATE_FN]) {
1172
- const validateFn = context[VALIDATE_FN];
1173
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1174
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
1175
- extendContext({
1176
- [VALIDATION_ERRORS]: errors,
1177
- });
1178
- breakContextBuilding();
1179
- }
1180
- }
1181
- },
1182
- onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1183
- // If validation errors are set in context
1184
- if (contextValue[VALIDATION_ERRORS]) {
1185
- setResultAndStopExecution({
1186
- errors: contextValue[VALIDATION_ERRORS],
1187
- });
1188
- }
1100
+ schemaPromise.then(schemaObj => {
1101
+ setSchema(schemaObj);
1102
+ });
1189
1103
  },
1190
1104
  };
1191
1105
  };
@@ -1382,7 +1296,6 @@ exports.isIntrospectionOperation = isIntrospectionOperation;
1382
1296
  exports.isIntrospectionOperationString = isIntrospectionOperationString;
1383
1297
  exports.isOperationDefinition = isOperationDefinition;
1384
1298
  exports.isPluginEnabled = isPluginEnabled;
1385
- exports.isPromise = isPromise;
1386
1299
  exports.makeExecute = makeExecute;
1387
1300
  exports.makeSubscribe = makeSubscribe;
1388
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,101 +1083,19 @@ const useSchema = (schema) => {
1087
1083
  },
1088
1084
  };
1089
1085
  };
1090
- const VALIDATE_FN = Symbol('VALIDATE_FN');
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
- const schema$ = schemaLoader(context);
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 promise is still ongoing
1109
- if (schemaSet$ != null) {
1110
- if (validateSchema) {
1111
- extendContext({
1112
- [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1113
- });
1114
- }
1115
- setValidationFn(() => []);
1116
- }
1117
- },
1118
- async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1119
- // If schemaSet promise is still ongoing
1120
- if (context[VALIDATE_FN]) {
1121
- const validateFn = context[VALIDATE_FN];
1122
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1123
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
1124
- extendContext({
1125
- [VALIDATION_ERRORS]: errors,
1126
- });
1127
- breakContextBuilding();
1128
- }
1129
- }
1130
- },
1131
- onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1132
- // If validation errors are set in context
1133
- if (contextValue[VALIDATION_ERRORS]) {
1134
- setResultAndStopExecution({
1135
- errors: contextValue[VALIDATION_ERRORS],
1136
- });
1137
- }
1089
+ setSchema(schemaLoader(context));
1138
1090
  },
1139
1091
  };
1140
1092
  };
1141
- const useAsyncSchema = (schema$, validateSchema = true) => {
1142
- let schemaSet$;
1093
+ const useAsyncSchema = (schemaPromise) => {
1143
1094
  return {
1144
1095
  onPluginInit({ setSchema }) {
1145
- if (isPromise(schema$)) {
1146
- schemaSet$ = schema$.then(schemaObj => {
1147
- setSchema(schemaObj);
1148
- return schemaObj;
1149
- });
1150
- }
1151
- else {
1152
- setSchema(schema$);
1153
- }
1154
- },
1155
- onValidate({ validateFn, params, setValidationFn, extendContext }) {
1156
- if (schemaSet$ != null) {
1157
- if (validateSchema) {
1158
- extendContext({
1159
- [VALIDATE_FN]: () => schemaSet$.then(schema => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options)),
1160
- });
1161
- }
1162
- setValidationFn(() => []);
1163
- }
1164
- },
1165
- async onContextBuilding({ context, extendContext, breakContextBuilding }) {
1166
- // If schemaSet promise is still ongoing
1167
- if (context[VALIDATE_FN]) {
1168
- const validateFn = context[VALIDATE_FN];
1169
- const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn();
1170
- if (errors === null || errors === void 0 ? void 0 : errors.length) {
1171
- extendContext({
1172
- [VALIDATION_ERRORS]: errors,
1173
- });
1174
- breakContextBuilding();
1175
- }
1176
- }
1177
- },
1178
- onExecute({ args: { contextValue }, setResultAndStopExecution }) {
1179
- // If validation errors are set in context
1180
- if (contextValue[VALIDATION_ERRORS]) {
1181
- setResultAndStopExecution({
1182
- errors: contextValue[VALIDATION_ERRORS],
1183
- });
1184
- }
1096
+ schemaPromise.then(schemaObj => {
1097
+ setSchema(schemaObj);
1098
+ });
1185
1099
  },
1186
1100
  };
1187
1101
  };
@@ -1355,4 +1269,4 @@ const useImmediateIntrospection = () => {
1355
1269
  };
1356
1270
  };
1357
1271
 
1358
- export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, isPromise, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.3.2-alpha-fd02291.0",
3
+ "version": "2.3.2",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
@@ -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?: Record<string, any>);
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;
@@ -1,5 +1,5 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
- import { DefaultContext, Maybe, Plugin, PromiseOrValue } from '@envelop/types';
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>) => PromiseOrValue<GraphQLSchema>, validateSchema?: boolean) => Plugin;
5
- export declare const useAsyncSchema: (schema$: PromiseOrValue<GraphQLSchema>, validateSchema?: boolean) => Plugin;
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>;