@envelop/core 2.4.0-alpha-e9434aa.0 → 2.4.0-alpha-731c100.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/esm/create.js CHANGED
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.envelop = void 0;
4
- const enable_if_js_1 = require("./enable-if.js");
5
- const orchestrator_js_1 = require("./orchestrator.js");
6
- const traced_orchestrator_js_1 = require("./traced-orchestrator.js");
7
- function envelop(options) {
8
- const plugins = options.plugins.filter(enable_if_js_1.isPluginEnabled);
9
- let orchestrator = (0, orchestrator_js_1.createEnvelopOrchestrator)(plugins);
1
+ import { isPluginEnabled } from './enable-if.js';
2
+ import { createEnvelopOrchestrator } from './orchestrator.js';
3
+ import { traceOrchestrator } from './traced-orchestrator.js';
4
+ export function envelop(options) {
5
+ const plugins = options.plugins.filter(isPluginEnabled);
6
+ let orchestrator = createEnvelopOrchestrator(plugins);
10
7
  if (options.enableInternalTracing) {
11
- orchestrator = (0, traced_orchestrator_js_1.traceOrchestrator)(orchestrator);
8
+ orchestrator = traceOrchestrator(orchestrator);
12
9
  }
13
10
  const getEnveloped = (initialContext = {}) => {
14
11
  const typedOrchestrator = orchestrator;
@@ -25,4 +22,3 @@ function envelop(options) {
25
22
  getEnveloped._plugins = plugins;
26
23
  return getEnveloped;
27
24
  }
28
- exports.envelop = envelop;
package/esm/enable-if.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enableIf = exports.isPluginEnabled = void 0;
4
1
  /**
5
2
  * This enum is used only internally in order to create nominal type for the disabled plugin
6
3
  */
@@ -8,17 +5,15 @@ var EnableIfBranded;
8
5
  (function (EnableIfBranded) {
9
6
  EnableIfBranded[EnableIfBranded["DisabledPlugin"] = 0] = "DisabledPlugin";
10
7
  })(EnableIfBranded || (EnableIfBranded = {}));
11
- function isPluginEnabled(t) {
8
+ export function isPluginEnabled(t) {
12
9
  return t !== EnableIfBranded.DisabledPlugin && t !== null;
13
10
  }
14
- exports.isPluginEnabled = isPluginEnabled;
15
11
  /**
16
12
  * Utility function to enable a plugin.
17
13
  */
18
- function enableIf(condition, plugin) {
14
+ export function enableIf(condition, plugin) {
19
15
  if (condition) {
20
16
  return typeof plugin === 'function' ? plugin() : plugin;
21
17
  }
22
18
  return EnableIfBranded.DisabledPlugin;
23
19
  }
24
- exports.enableIf = enableIf;
package/esm/index.js CHANGED
@@ -1,29 +1,13 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("@envelop/types"), exports);
18
- __exportStar(require("./create.js"), exports);
19
- __exportStar(require("./utils.js"), exports);
20
- __exportStar(require("./plugins/use-envelop.js"), exports);
21
- __exportStar(require("./plugins/use-logger.js"), exports);
22
- __exportStar(require("./plugins/use-timing.js"), exports);
23
- __exportStar(require("./plugins/use-schema.js"), exports);
24
- __exportStar(require("./plugins/use-error-handler.js"), exports);
25
- __exportStar(require("./plugins/use-extend-context.js"), exports);
26
- __exportStar(require("./plugins/use-payload-formatter.js"), exports);
27
- __exportStar(require("./plugins/use-masked-errors.js"), exports);
28
- __exportStar(require("./plugins/use-immediate-introspection.js"), exports);
29
- __exportStar(require("./enable-if.js"), exports);
1
+ export * from '@envelop/types';
2
+ export * from './create.js';
3
+ export * from './utils.js';
4
+ export * from './plugins/use-envelop.js';
5
+ export * from './plugins/use-logger.js';
6
+ export * from './plugins/use-timing.js';
7
+ export * from './plugins/use-schema.js';
8
+ export * from './plugins/use-error-handler.js';
9
+ export * from './plugins/use-extend-context.js';
10
+ export * from './plugins/use-payload-formatter.js';
11
+ export * from './plugins/use-masked-errors.js';
12
+ export * from './plugins/use-immediate-introspection.js';
13
+ export * from './enable-if.js';
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEnvelopOrchestrator = void 0;
4
- const graphql_1 = require("graphql");
5
- const traced_schema_js_1 = require("./traced-schema.js");
6
- const utils_js_1 = require("./utils.js");
7
- function createEnvelopOrchestrator(plugins) {
1
+ import { execute, parse, specifiedRules, subscribe, validate, } from 'graphql';
2
+ import { prepareTracedSchema, resolversHooksSymbol } from './traced-schema.js';
3
+ import { errorAsyncIterator, finalAsyncIterator, makeExecute, makeSubscribe, mapAsyncIterator, isAsyncIterable, } from './utils.js';
4
+ export function createEnvelopOrchestrator(plugins) {
8
5
  let schema = null;
9
6
  let initDone = false;
10
7
  const onResolversHandlers = [];
@@ -18,7 +15,7 @@ function createEnvelopOrchestrator(plugins) {
18
15
  // here not to call the same plugin that initiated the schema switch.
19
16
  const replaceSchema = (newSchema, ignorePluginIndex = -1) => {
20
17
  if (onResolversHandlers.length) {
21
- (0, traced_schema_js_1.prepareTracedSchema)(newSchema);
18
+ prepareTracedSchema(newSchema);
22
19
  }
23
20
  schema = newSchema;
24
21
  if (initDone) {
@@ -82,7 +79,7 @@ function createEnvelopOrchestrator(plugins) {
82
79
  const customParse = beforeCallbacks.parse.length
83
80
  ? initialContext => (source, parseOptions) => {
84
81
  let result = null;
85
- let parseFn = graphql_1.parse;
82
+ let parseFn = parse;
86
83
  const context = initialContext;
87
84
  const afterCalls = [];
88
85
  for (const onParse of beforeCallbacks.parse) {
@@ -130,11 +127,11 @@ function createEnvelopOrchestrator(plugins) {
130
127
  }
131
128
  return result;
132
129
  }
133
- : () => graphql_1.parse;
130
+ : () => parse;
134
131
  const customValidate = beforeCallbacks.validate.length
135
132
  ? initialContext => (schema, documentAST, rules, typeInfo, validationOptions) => {
136
133
  let actualRules = rules ? [...rules] : undefined;
137
- let validateFn = graphql_1.validate;
134
+ let validateFn = validate;
138
135
  let result = null;
139
136
  const context = initialContext;
140
137
  const afterCalls = [];
@@ -154,7 +151,7 @@ function createEnvelopOrchestrator(plugins) {
154
151
  validateFn,
155
152
  addValidationRule: rule => {
156
153
  if (!actualRules) {
157
- actualRules = [...graphql_1.specifiedRules];
154
+ actualRules = [...specifiedRules];
158
155
  }
159
156
  actualRules.push(rule);
160
157
  },
@@ -186,7 +183,7 @@ function createEnvelopOrchestrator(plugins) {
186
183
  }
187
184
  return result;
188
185
  }
189
- : () => graphql_1.validate;
186
+ : () => validate;
190
187
  const customContextFactory = beforeCallbacks.context.length
191
188
  ? initialContext => async (orchestratorCtx) => {
192
189
  const afterCalls = [];
@@ -238,8 +235,8 @@ function createEnvelopOrchestrator(plugins) {
238
235
  : initialContext => orchestratorCtx => orchestratorCtx ? { ...initialContext, ...orchestratorCtx } : initialContext;
239
236
  const useCustomSubscribe = beforeCallbacks.subscribe.length || onResolversHandlers.length;
240
237
  const customSubscribe = useCustomSubscribe
241
- ? (0, utils_js_1.makeSubscribe)(async (args) => {
242
- let subscribeFn = graphql_1.subscribe;
238
+ ? makeSubscribe(async (args) => {
239
+ let subscribeFn = subscribe;
243
240
  const afterCalls = [];
244
241
  const subscribeErrorHandlers = [];
245
242
  let context = args.contextValue || {};
@@ -271,7 +268,7 @@ function createEnvelopOrchestrator(plugins) {
271
268
  }
272
269
  }
273
270
  if (onResolversHandlers.length) {
274
- context[traced_schema_js_1.resolversHooksSymbol] = onResolversHandlers;
271
+ context[resolversHooksSymbol] = onResolversHandlers;
275
272
  }
276
273
  if (result === undefined) {
277
274
  result = await subscribeFn({
@@ -300,8 +297,8 @@ function createEnvelopOrchestrator(plugins) {
300
297
  }
301
298
  }
302
299
  }
303
- if (onNextHandler.length && (0, utils_js_1.isAsyncIterable)(result)) {
304
- result = (0, utils_js_1.mapAsyncIterator)(result, async (result) => {
300
+ if (onNextHandler.length && isAsyncIterable(result)) {
301
+ result = mapAsyncIterator(result, async (result) => {
305
302
  for (const onNext of onNextHandler) {
306
303
  await onNext({
307
304
  args: args,
@@ -312,15 +309,15 @@ function createEnvelopOrchestrator(plugins) {
312
309
  return result;
313
310
  });
314
311
  }
315
- if (onEndHandler.length && (0, utils_js_1.isAsyncIterable)(result)) {
316
- result = (0, utils_js_1.finalAsyncIterator)(result, () => {
312
+ if (onEndHandler.length && isAsyncIterable(result)) {
313
+ result = finalAsyncIterator(result, () => {
317
314
  for (const onEnd of onEndHandler) {
318
315
  onEnd();
319
316
  }
320
317
  });
321
318
  }
322
- if (subscribeErrorHandlers.length && (0, utils_js_1.isAsyncIterable)(result)) {
323
- result = (0, utils_js_1.errorAsyncIterator)(result, err => {
319
+ if (subscribeErrorHandlers.length && isAsyncIterable(result)) {
320
+ result = errorAsyncIterator(result, err => {
324
321
  let error = err;
325
322
  for (const handler of subscribeErrorHandlers) {
326
323
  handler({
@@ -335,11 +332,11 @@ function createEnvelopOrchestrator(plugins) {
335
332
  }
336
333
  return result;
337
334
  })
338
- : (0, utils_js_1.makeSubscribe)(graphql_1.subscribe);
335
+ : makeSubscribe(subscribe);
339
336
  const useCustomExecute = beforeCallbacks.execute.length || onResolversHandlers.length;
340
337
  const customExecute = useCustomExecute
341
- ? (0, utils_js_1.makeExecute)(async (args) => {
342
- let executeFn = graphql_1.execute;
338
+ ? makeExecute(async (args) => {
339
+ let executeFn = execute;
343
340
  let result;
344
341
  const afterCalls = [];
345
342
  let context = args.contextValue || {};
@@ -373,7 +370,7 @@ function createEnvelopOrchestrator(plugins) {
373
370
  }
374
371
  }
375
372
  if (onResolversHandlers.length) {
376
- context[traced_schema_js_1.resolversHooksSymbol] = onResolversHandlers;
373
+ context[resolversHooksSymbol] = onResolversHandlers;
377
374
  }
378
375
  if (result === undefined) {
379
376
  result = (await executeFn({
@@ -400,8 +397,8 @@ function createEnvelopOrchestrator(plugins) {
400
397
  }
401
398
  }
402
399
  }
403
- if (onNextHandler.length && (0, utils_js_1.isAsyncIterable)(result)) {
404
- result = (0, utils_js_1.mapAsyncIterator)(result, async (result) => {
400
+ if (onNextHandler.length && isAsyncIterable(result)) {
401
+ result = mapAsyncIterator(result, async (result) => {
405
402
  for (const onNext of onNextHandler) {
406
403
  await onNext({
407
404
  args: args,
@@ -414,8 +411,8 @@ function createEnvelopOrchestrator(plugins) {
414
411
  return result;
415
412
  });
416
413
  }
417
- if (onEndHandler.length && (0, utils_js_1.isAsyncIterable)(result)) {
418
- result = (0, utils_js_1.finalAsyncIterator)(result, () => {
414
+ if (onEndHandler.length && isAsyncIterable(result)) {
415
+ result = finalAsyncIterator(result, () => {
419
416
  for (const onEnd of onEndHandler) {
420
417
  onEnd();
421
418
  }
@@ -423,7 +420,7 @@ function createEnvelopOrchestrator(plugins) {
423
420
  }
424
421
  return result;
425
422
  })
426
- : (0, utils_js_1.makeExecute)(graphql_1.execute);
423
+ : makeExecute(execute);
427
424
  initDone = true;
428
425
  // This is done in order to trigger the first schema available, to allow plugins that needs the schema
429
426
  // eagerly to have it.
@@ -448,4 +445,3 @@ function createEnvelopOrchestrator(plugins) {
448
445
  contextFactory: customContextFactory,
449
446
  };
450
447
  }
451
- exports.createEnvelopOrchestrator = createEnvelopOrchestrator;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useEnvelop = void 0;
4
- const useEnvelop = (envelop) => {
1
+ export const useEnvelop = (envelop) => {
5
2
  return {
6
3
  onPluginInit({ addPlugin }) {
7
4
  for (const plugin of envelop._plugins) {
@@ -10,4 +7,3 @@ const useEnvelop = (envelop) => {
10
7
  },
11
8
  };
12
9
  };
13
- exports.useEnvelop = useEnvelop;
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useErrorHandler = void 0;
4
- const utils_js_1 = require("../utils.js");
1
+ import { handleStreamOrSingleExecutionResult } from '../utils.js';
5
2
  const makeHandleResult = (errorHandler) => ({ result, args }) => {
6
3
  var _a;
7
4
  if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
8
5
  errorHandler(result.errors, args);
9
6
  }
10
7
  };
11
- const useErrorHandler = (errorHandler) => ({
8
+ export const useErrorHandler = (errorHandler) => ({
12
9
  onExecute() {
13
10
  const handleResult = makeHandleResult(errorHandler);
14
11
  return {
15
12
  onExecuteDone(payload) {
16
- return (0, utils_js_1.handleStreamOrSingleExecutionResult)(payload, handleResult);
13
+ return handleStreamOrSingleExecutionResult(payload, handleResult);
17
14
  },
18
15
  };
19
16
  },
20
17
  });
21
- exports.useErrorHandler = useErrorHandler;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useExtendContext = void 0;
4
- const useExtendContext = (contextFactory) => ({
1
+ export const useExtendContext = (contextFactory) => ({
5
2
  async onContextBuilding({ context, extendContext }) {
6
3
  extendContext((await contextFactory(context)));
7
4
  },
8
5
  });
9
- exports.useExtendContext = useExtendContext;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useImmediateIntrospection = void 0;
4
- const graphql_1 = require("graphql");
1
+ import { BREAK } from 'graphql';
5
2
  const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
6
3
  const rootQueryType = ctx.getSchema().getQueryType();
7
4
  const rootMutationType = ctx.getSchema().getMutationType();
@@ -14,7 +11,7 @@ const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) =
14
11
  const isSubscription = parentType === rootSubscriptionType;
15
12
  if ((isQuery && !field.name.value.startsWith('__')) || isMutation || isSubscription) {
16
13
  onNonIntrospectionField();
17
- return graphql_1.BREAK;
14
+ return BREAK;
18
15
  }
19
16
  return undefined;
20
17
  },
@@ -25,7 +22,7 @@ const fastIntroSpectionSymbol = Symbol('fastIntrospection');
25
22
  * In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
26
23
  * With this plugin any further context extensions will be skipped.
27
24
  */
28
- const useImmediateIntrospection = () => {
25
+ export const useImmediateIntrospection = () => {
29
26
  return {
30
27
  onValidate({ addValidationRule }) {
31
28
  let isIntrospectionOnly = true;
@@ -47,4 +44,3 @@ const useImmediateIntrospection = () => {
47
44
  },
48
45
  };
49
46
  };
50
- exports.useImmediateIntrospection = useImmediateIntrospection;
@@ -1,25 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useLogger = void 0;
4
- const utils_js_1 = require("../utils.js");
1
+ import { envelopIsIntrospectionSymbol, isIntrospectionOperationString } from '../utils.js';
5
2
  const DEFAULT_OPTIONS = {
6
3
  logFn: console.log,
7
4
  };
8
- const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
5
+ export const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
9
6
  const options = {
10
7
  DEFAULT_OPTIONS,
11
8
  ...rawOptions,
12
9
  };
13
10
  return {
14
11
  onParse({ extendContext, params }) {
15
- if (options.skipIntrospection && (0, utils_js_1.isIntrospectionOperationString)(params.source)) {
12
+ if (options.skipIntrospection && isIntrospectionOperationString(params.source)) {
16
13
  extendContext({
17
- [utils_js_1.envelopIsIntrospectionSymbol]: true,
14
+ [envelopIsIntrospectionSymbol]: true,
18
15
  });
19
16
  }
20
17
  },
21
18
  onExecute({ args }) {
22
- if (args.contextValue[utils_js_1.envelopIsIntrospectionSymbol]) {
19
+ if (args.contextValue[envelopIsIntrospectionSymbol]) {
23
20
  return;
24
21
  }
25
22
  options.logFn('execute-start', { args });
@@ -30,7 +27,7 @@ const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
30
27
  };
31
28
  },
32
29
  onSubscribe({ args }) {
33
- if (args.contextValue[utils_js_1.envelopIsIntrospectionSymbol]) {
30
+ if (args.contextValue[envelopIsIntrospectionSymbol]) {
34
31
  return;
35
32
  }
36
33
  options.logFn('subscribe-start', { args });
@@ -42,4 +39,3 @@ const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
42
39
  },
43
40
  };
44
41
  };
45
- exports.useLogger = useLogger;
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMaskedErrors = exports.formatError = exports.EnvelopError = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
- const graphql_1 = require("graphql");
5
- const utils_js_1 = require("../utils.js");
6
- exports.DEFAULT_ERROR_MESSAGE = 'Unexpected error.';
7
- class EnvelopError extends graphql_1.GraphQLError {
1
+ import { GraphQLError } from 'graphql';
2
+ import { handleStreamOrSingleExecutionResult } from '../utils.js';
3
+ export const DEFAULT_ERROR_MESSAGE = 'Unexpected error.';
4
+ export class EnvelopError extends GraphQLError {
8
5
  constructor(message, extensions) {
9
6
  super(message, undefined, undefined, undefined, undefined, undefined, extensions);
10
7
  }
11
8
  }
12
- exports.EnvelopError = EnvelopError;
13
- const formatError = (err, message, isDev) => {
9
+ export const formatError = (err, message, isDev) => {
14
10
  var _a, _b, _c, _d;
15
- if (err instanceof graphql_1.GraphQLError) {
11
+ if (err instanceof GraphQLError) {
16
12
  if (
17
13
  /** execution error */
18
14
  (err.originalError && err.originalError instanceof EnvelopError === false) ||
19
15
  /** validate and parse errors */
20
16
  (err.originalError === undefined && err instanceof EnvelopError === false)) {
21
- return new graphql_1.GraphQLError(message, err.nodes, err.source, err.positions, err.path, undefined, isDev
17
+ return new GraphQLError(message, err.nodes, err.source, err.positions, err.path, undefined, isDev
22
18
  ? {
23
19
  originalError: {
24
20
  message: (_b = (_a = err.originalError) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : err.message,
@@ -29,18 +25,17 @@ const formatError = (err, message, isDev) => {
29
25
  }
30
26
  return err;
31
27
  }
32
- return new graphql_1.GraphQLError(message);
28
+ return new GraphQLError(message);
33
29
  };
34
- exports.formatError = formatError;
35
30
  const makeHandleResult = (format, message, isDev) => ({ result, setResult }) => {
36
31
  if (result.errors != null) {
37
32
  setResult({ ...result, errors: result.errors.map(error => format(error, message, isDev)) });
38
33
  }
39
34
  };
40
- const useMaskedErrors = (opts) => {
35
+ export const useMaskedErrors = (opts) => {
41
36
  var _a, _b;
42
- const format = (_a = opts === null || opts === void 0 ? void 0 : opts.formatError) !== null && _a !== void 0 ? _a : exports.formatError;
43
- const message = (opts === null || opts === void 0 ? void 0 : opts.errorMessage) || exports.DEFAULT_ERROR_MESSAGE;
37
+ const format = (_a = opts === null || opts === void 0 ? void 0 : opts.formatError) !== null && _a !== void 0 ? _a : formatError;
38
+ const message = (opts === null || opts === void 0 ? void 0 : opts.errorMessage) || DEFAULT_ERROR_MESSAGE;
44
39
  // eslint-disable-next-line dot-notation
45
40
  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);
46
41
  const handleResult = makeHandleResult(format, message, isDev);
@@ -65,26 +60,25 @@ const useMaskedErrors = (opts) => {
65
60
  : undefined,
66
61
  onPluginInit(context) {
67
62
  context.registerContextErrorHandler(({ error, setError }) => {
68
- setError((0, exports.formatError)(error, message, isDev));
63
+ setError(formatError(error, message, isDev));
69
64
  });
70
65
  },
71
66
  onExecute() {
72
67
  return {
73
68
  onExecuteDone(payload) {
74
- return (0, utils_js_1.handleStreamOrSingleExecutionResult)(payload, handleResult);
69
+ return handleStreamOrSingleExecutionResult(payload, handleResult);
75
70
  },
76
71
  };
77
72
  },
78
73
  onSubscribe() {
79
74
  return {
80
75
  onSubscribeResult(payload) {
81
- return (0, utils_js_1.handleStreamOrSingleExecutionResult)(payload, handleResult);
76
+ return handleStreamOrSingleExecutionResult(payload, handleResult);
82
77
  },
83
78
  onSubscribeError({ error, setError }) {
84
- setError((0, exports.formatError)(error, message, isDev));
79
+ setError(formatError(error, message, isDev));
85
80
  },
86
81
  };
87
82
  },
88
83
  };
89
84
  };
90
- exports.useMaskedErrors = useMaskedErrors;
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePayloadFormatter = void 0;
4
- const utils_js_1 = require("../utils.js");
1
+ import { handleStreamOrSingleExecutionResult } from '../utils.js';
5
2
  const makeHandleResult = (formatter) => ({ args, result, setResult, }) => {
6
3
  const modified = formatter(result, args);
7
4
  if (modified !== false) {
8
5
  setResult(modified);
9
6
  }
10
7
  };
11
- const usePayloadFormatter = (formatter) => ({
8
+ export const usePayloadFormatter = (formatter) => ({
12
9
  onExecute() {
13
10
  const handleResult = makeHandleResult(formatter);
14
11
  return {
15
12
  onExecuteDone(payload) {
16
- return (0, utils_js_1.handleStreamOrSingleExecutionResult)(payload, handleResult);
13
+ return handleStreamOrSingleExecutionResult(payload, handleResult);
17
14
  },
18
15
  };
19
16
  },
20
17
  });
21
- exports.usePayloadFormatter = usePayloadFormatter;
@@ -1,23 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAsyncSchema = exports.useLazyLoadedSchema = exports.useSchema = void 0;
4
- const useSchema = (schema) => {
1
+ export const useSchema = (schema) => {
5
2
  return {
6
3
  onPluginInit({ setSchema }) {
7
4
  setSchema(schema);
8
5
  },
9
6
  };
10
7
  };
11
- exports.useSchema = useSchema;
12
- const useLazyLoadedSchema = (schemaLoader) => {
8
+ export const useLazyLoadedSchema = (schemaLoader) => {
13
9
  return {
14
10
  onEnveloped({ setSchema, context }) {
15
11
  setSchema(schemaLoader(context));
16
12
  },
17
13
  };
18
14
  };
19
- exports.useLazyLoadedSchema = useLazyLoadedSchema;
20
- const useAsyncSchema = (schemaPromise) => {
15
+ export const useAsyncSchema = (schemaPromise) => {
21
16
  return {
22
17
  onPluginInit({ setSchema }) {
23
18
  schemaPromise.then(schemaObj => {
@@ -26,4 +21,3 @@ const useAsyncSchema = (schemaPromise) => {
26
21
  },
27
22
  };
28
23
  };
29
- exports.useAsyncSchema = useAsyncSchema;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTiming = void 0;
4
- const graphql_1 = require("graphql");
5
- const utils_js_1 = require("../utils.js");
1
+ import { getOperationAST } from 'graphql';
2
+ import { isIntrospectionOperationString, envelopIsIntrospectionSymbol } from '../utils.js';
6
3
  const HR_TO_NS = 1e9;
7
4
  const NS_TO_MS = 1e6;
8
5
  const DEFAULT_OPTIONS = {
9
6
  onExecutionMeasurement: (args, timing) => console.log(`Operation execution "${args.operationName}" done in ${timing.ms}ms`),
10
7
  onSubscriptionMeasurement: (args, timing) => console.log(`Operation subscription "${args.operationName}" done in ${timing.ms}ms`),
11
8
  onParsingMeasurement: (source, timing) => console.log(`Parsing "${source}" done in ${timing.ms}ms`),
12
- onValidationMeasurement: (document, timing) => { var _a, _b; return console.log(`Validation "${((_b = (_a = (0, graphql_1.getOperationAST)(document)) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) || '-'}" done in ${timing.ms}ms`); },
9
+ onValidationMeasurement: (document, timing) => { var _a, _b; return console.log(`Validation "${((_b = (_a = getOperationAST(document)) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) || '-'}" done in ${timing.ms}ms`); },
13
10
  onResolverMeasurement: (info, timing) => console.log(`\tResolver of "${info.parentType.toString()}.${info.fieldName}" done in ${timing.ms}ms`),
14
11
  onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),
15
12
  };
@@ -23,7 +20,7 @@ const deltaFrom = (hrtime) => {
23
20
  },
24
21
  };
25
22
  };
26
- const useTiming = (rawOptions) => {
23
+ export const useTiming = (rawOptions) => {
27
24
  const options = {
28
25
  ...DEFAULT_OPTIONS,
29
26
  ...(rawOptions || {}),
@@ -31,7 +28,7 @@ const useTiming = (rawOptions) => {
31
28
  const result = {};
32
29
  if (options.onContextBuildingMeasurement) {
33
30
  result.onContextBuilding = ({ context }) => {
34
- if (context[utils_js_1.envelopIsIntrospectionSymbol]) {
31
+ if (context[envelopIsIntrospectionSymbol]) {
35
32
  return;
36
33
  }
37
34
  const contextStartTime = process.hrtime();
@@ -42,9 +39,9 @@ const useTiming = (rawOptions) => {
42
39
  }
43
40
  if (options.onParsingMeasurement) {
44
41
  result.onParse = ({ params, extendContext }) => {
45
- if (options.skipIntrospection && (0, utils_js_1.isIntrospectionOperationString)(params.source)) {
42
+ if (options.skipIntrospection && isIntrospectionOperationString(params.source)) {
46
43
  extendContext({
47
- [utils_js_1.envelopIsIntrospectionSymbol]: true,
44
+ [envelopIsIntrospectionSymbol]: true,
48
45
  });
49
46
  return;
50
47
  }
@@ -56,7 +53,7 @@ const useTiming = (rawOptions) => {
56
53
  }
57
54
  if (options.onValidationMeasurement) {
58
55
  result.onValidate = ({ params, context }) => {
59
- if (context[utils_js_1.envelopIsIntrospectionSymbol]) {
56
+ if (context[envelopIsIntrospectionSymbol]) {
60
57
  return;
61
58
  }
62
59
  const validateStartTime = process.hrtime();
@@ -68,7 +65,7 @@ const useTiming = (rawOptions) => {
68
65
  if (options.onExecutionMeasurement) {
69
66
  if (options.onResolverMeasurement) {
70
67
  result.onExecute = ({ args }) => {
71
- if (args.contextValue[utils_js_1.envelopIsIntrospectionSymbol]) {
68
+ if (args.contextValue[envelopIsIntrospectionSymbol]) {
72
69
  return;
73
70
  }
74
71
  const executeStartTime = process.hrtime();
@@ -87,7 +84,7 @@ const useTiming = (rawOptions) => {
87
84
  }
88
85
  else {
89
86
  result.onExecute = ({ args }) => {
90
- if (args.contextValue[utils_js_1.envelopIsIntrospectionSymbol]) {
87
+ if (args.contextValue[envelopIsIntrospectionSymbol]) {
91
88
  return;
92
89
  }
93
90
  const executeStartTime = process.hrtime();
@@ -102,7 +99,7 @@ const useTiming = (rawOptions) => {
102
99
  if (options.onSubscriptionMeasurement) {
103
100
  if (options.onResolverMeasurement) {
104
101
  result.onSubscribe = ({ args }) => {
105
- if (args.contextValue[utils_js_1.envelopIsIntrospectionSymbol]) {
102
+ if (args.contextValue[envelopIsIntrospectionSymbol]) {
106
103
  return;
107
104
  }
108
105
  const subscribeStartTime = process.hrtime();
@@ -121,7 +118,7 @@ const useTiming = (rawOptions) => {
121
118
  }
122
119
  else {
123
120
  result.onSubscribe = ({ args }) => {
124
- if (args.contextValue[utils_js_1.envelopIsIntrospectionSymbol]) {
121
+ if (args.contextValue[envelopIsIntrospectionSymbol]) {
125
122
  return;
126
123
  }
127
124
  const subscribeStartTime = process.hrtime();
@@ -135,4 +132,3 @@ const useTiming = (rawOptions) => {
135
132
  }
136
133
  return result;
137
134
  };
138
- exports.useTiming = useTiming;
@@ -1,9 +1,6 @@
1
- "use strict";
2
1
  var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.traceOrchestrator = void 0;
5
- const graphql_1 = require("graphql");
6
- const utils_js_1 = require("./utils.js");
2
+ import { GraphQLSchema } from 'graphql';
3
+ import { isAsyncIterable } from './utils.js';
7
4
  const getTimestamp = typeof globalThis !== 'undefined' && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.performance) === null || _a === void 0 ? void 0 : _a.now) ? () => globalThis.performance.now() : () => Date.now();
8
5
  const measure = () => {
9
6
  const start = getTimestamp();
@@ -13,7 +10,7 @@ const measure = () => {
13
10
  };
14
11
  };
15
12
  const tracingSymbol = Symbol('envelopTracing');
16
- function traceOrchestrator(orchestrator) {
13
+ export function traceOrchestrator(orchestrator) {
17
14
  const createTracer = (name, ctx) => {
18
15
  const end = measure();
19
16
  return () => {
@@ -59,7 +56,7 @@ function traceOrchestrator(orchestrator) {
59
56
  };
60
57
  },
61
58
  execute: async (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
62
- const args = argsOrSchema instanceof graphql_1.GraphQLSchema
59
+ const args = argsOrSchema instanceof GraphQLSchema
63
60
  ? {
64
61
  schema: argsOrSchema,
65
62
  document: document,
@@ -77,7 +74,7 @@ function traceOrchestrator(orchestrator) {
77
74
  try {
78
75
  const result = await orchestrator.execute(args);
79
76
  done();
80
- if (!(0, utils_js_1.isAsyncIterable)(result)) {
77
+ if (!isAsyncIterable(result)) {
81
78
  result.extensions = result.extensions || {};
82
79
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
80
  // @ts-ignore GraphQL.js types contextValue as unknown
@@ -95,7 +92,7 @@ function traceOrchestrator(orchestrator) {
95
92
  }
96
93
  },
97
94
  subscribe: async (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
98
- const args = argsOrSchema instanceof graphql_1.GraphQLSchema
95
+ const args = argsOrSchema instanceof GraphQLSchema
99
96
  ? {
100
97
  schema: argsOrSchema,
101
98
  document: document,
@@ -131,4 +128,3 @@ function traceOrchestrator(orchestrator) {
131
128
  },
132
129
  };
133
130
  }
134
- exports.traceOrchestrator = traceOrchestrator;
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareTracedSchema = exports.resolversHooksSymbol = exports.trackedSchemaSymbol = void 0;
4
- const graphql_1 = require("graphql");
5
- exports.trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
6
- exports.resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
7
- function prepareTracedSchema(schema) {
8
- if (!schema || schema[exports.trackedSchemaSymbol]) {
1
+ import { defaultFieldResolver, isIntrospectionType, isObjectType } from 'graphql';
2
+ export const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
3
+ export const resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
4
+ export function prepareTracedSchema(schema) {
5
+ if (!schema || schema[trackedSchemaSymbol]) {
9
6
  return;
10
7
  }
11
- schema[exports.trackedSchemaSymbol] = true;
8
+ schema[trackedSchemaSymbol] = true;
12
9
  const entries = Object.values(schema.getTypeMap());
13
10
  for (const type of entries) {
14
- if (!(0, graphql_1.isIntrospectionType)(type) && (0, graphql_1.isObjectType)(type)) {
11
+ if (!isIntrospectionType(type) && isObjectType(type)) {
15
12
  const fields = Object.values(type.getFields());
16
13
  for (const field of fields) {
17
- let resolverFn = (field.resolve || graphql_1.defaultFieldResolver);
14
+ let resolverFn = (field.resolve || defaultFieldResolver);
18
15
  field.resolve = async (root, args, context, info) => {
19
- if (context && context[exports.resolversHooksSymbol]) {
20
- const hooks = context[exports.resolversHooksSymbol];
16
+ if (context && context[resolversHooksSymbol]) {
17
+ const hooks = context[resolversHooksSymbol];
21
18
  const afterCalls = [];
22
19
  for (const hook of hooks) {
23
20
  const afterFn = await hook({
@@ -65,4 +62,3 @@ function prepareTracedSchema(schema) {
65
62
  }
66
63
  }
67
64
  }
68
- exports.prepareTracedSchema = prepareTracedSchema;
package/esm/utils.js CHANGED
@@ -1,20 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorAsyncIterator = exports.finalAsyncIterator = exports.handleStreamOrSingleExecutionResult = exports.isAsyncIterable = exports.makeExecute = exports.mapAsyncIterator = exports.makeSubscribe = exports.isIntrospectionOperationString = exports.isIntrospectionDocument = exports.isIntrospectionOperation = exports.isOperationDefinition = exports.envelopIsIntrospectionSymbol = void 0;
4
- const graphql_1 = require("graphql");
5
- exports.envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
6
- function isOperationDefinition(def) {
7
- return def.kind === graphql_1.Kind.OPERATION_DEFINITION;
1
+ import { Kind, visit, BREAK, } from 'graphql';
2
+ export const envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
3
+ export function isOperationDefinition(def) {
4
+ return def.kind === Kind.OPERATION_DEFINITION;
8
5
  }
9
- exports.isOperationDefinition = isOperationDefinition;
10
- function isIntrospectionOperation(operation) {
6
+ export function isIntrospectionOperation(operation) {
11
7
  if (operation.kind === 'OperationDefinition') {
12
8
  let hasIntrospectionField = false;
13
- (0, graphql_1.visit)(operation, {
9
+ visit(operation, {
14
10
  Field: node => {
15
11
  if (node.name.value === '__schema') {
16
12
  hasIntrospectionField = true;
17
- return graphql_1.BREAK;
13
+ return BREAK;
18
14
  }
19
15
  },
20
16
  });
@@ -22,16 +18,13 @@ function isIntrospectionOperation(operation) {
22
18
  }
23
19
  return false;
24
20
  }
25
- exports.isIntrospectionOperation = isIntrospectionOperation;
26
- function isIntrospectionDocument(document) {
21
+ export function isIntrospectionDocument(document) {
27
22
  const operations = document.definitions.filter(isOperationDefinition);
28
23
  return operations.some(op => isIntrospectionOperation(op));
29
24
  }
30
- exports.isIntrospectionDocument = isIntrospectionDocument;
31
- function isIntrospectionOperationString(operation) {
25
+ export function isIntrospectionOperationString(operation) {
32
26
  return (typeof operation === 'string' ? operation : operation.body).indexOf('__schema') !== -1;
33
27
  }
34
- exports.isIntrospectionOperationString = isIntrospectionOperationString;
35
28
  function getSubscribeArgs(args) {
36
29
  return args.length === 1
37
30
  ? args[0]
@@ -49,9 +42,8 @@ function getSubscribeArgs(args) {
49
42
  /**
50
43
  * Utility function for making a subscribe function that handles polymorphic arguments.
51
44
  */
52
- const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs)));
53
- exports.makeSubscribe = makeSubscribe;
54
- function mapAsyncIterator(source, mapper) {
45
+ export const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs)));
46
+ export function mapAsyncIterator(source, mapper) {
55
47
  const iterator = source[Symbol.asyncIterator]();
56
48
  async function mapResult(result) {
57
49
  var _a;
@@ -96,7 +88,6 @@ function mapAsyncIterator(source, mapper) {
96
88
  };
97
89
  return stream;
98
90
  }
99
- exports.mapAsyncIterator = mapAsyncIterator;
100
91
  function getExecuteArgs(args) {
101
92
  return args.length === 1
102
93
  ? args[0]
@@ -114,20 +105,18 @@ function getExecuteArgs(args) {
114
105
  /**
115
106
  * Utility function for making a execute function that handles polymorphic arguments.
116
107
  */
117
- const makeExecute = (executeFn) => ((...polyArgs) => executeFn(getExecuteArgs(polyArgs)));
118
- exports.makeExecute = makeExecute;
108
+ export const makeExecute = (executeFn) => ((...polyArgs) => executeFn(getExecuteArgs(polyArgs)));
119
109
  /**
120
110
  * Returns true if the provided object implements the AsyncIterator protocol via
121
111
  * implementing a `Symbol.asyncIterator` method.
122
112
  *
123
113
  * Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
124
114
  */
125
- function isAsyncIterable(maybeAsyncIterable) {
115
+ export function isAsyncIterable(maybeAsyncIterable) {
126
116
  return (typeof maybeAsyncIterable === 'object' &&
127
117
  maybeAsyncIterable != null &&
128
118
  typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
129
119
  }
130
- exports.isAsyncIterable = isAsyncIterable;
131
120
  /**
132
121
  * A utility function for handling `onExecuteDone` hook result, for simplifying the handling of AsyncIterable returned from `execute`.
133
122
  *
@@ -135,7 +124,7 @@ exports.isAsyncIterable = isAsyncIterable;
135
124
  * @param fn The handler to be executed on each result
136
125
  * @returns a subscription for streamed results, or undefined in case of an non-async
137
126
  */
138
- function handleStreamOrSingleExecutionResult(payload, fn) {
127
+ export function handleStreamOrSingleExecutionResult(payload, fn) {
139
128
  if (isAsyncIterable(payload.result)) {
140
129
  return { onNext: fn };
141
130
  }
@@ -146,8 +135,7 @@ function handleStreamOrSingleExecutionResult(payload, fn) {
146
135
  });
147
136
  return undefined;
148
137
  }
149
- exports.handleStreamOrSingleExecutionResult = handleStreamOrSingleExecutionResult;
150
- function finalAsyncIterator(source, onFinal) {
138
+ export function finalAsyncIterator(source, onFinal) {
151
139
  const iterator = source[Symbol.asyncIterator]();
152
140
  let isDone = false;
153
141
  const stream = {
@@ -184,8 +172,7 @@ function finalAsyncIterator(source, onFinal) {
184
172
  };
185
173
  return stream;
186
174
  }
187
- exports.finalAsyncIterator = finalAsyncIterator;
188
- function errorAsyncIterator(source, onError) {
175
+ export function errorAsyncIterator(source, onError) {
189
176
  const iterator = source[Symbol.asyncIterator]();
190
177
  const stream = {
191
178
  [Symbol.asyncIterator]() {
@@ -218,4 +205,3 @@ function errorAsyncIterator(source, onError) {
218
205
  };
219
206
  return stream;
220
207
  }
221
- exports.errorAsyncIterator = errorAsyncIterator;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.4.0-alpha-e9434aa.0",
3
+ "version": "2.4.0-alpha-731c100.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.3.0-alpha-e9434aa.0"
9
+ "@envelop/types": "2.3.0-alpha-731c100.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",