@envelop/core 2.6.0 → 2.6.1-alpha-20220901205925-b1fd44a9

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.
Files changed (45) hide show
  1. package/cjs/create.js +7 -5
  2. package/cjs/index.js +3 -3
  3. package/cjs/orchestrator.js +20 -12
  4. package/cjs/plugins/use-error-handler.js +1 -2
  5. package/cjs/traced-schema.js +29 -7
  6. package/cjs/utils.js +8 -40
  7. package/esm/create.js +7 -5
  8. package/esm/index.js +1 -3
  9. package/esm/orchestrator.js +12 -4
  10. package/esm/plugins/use-error-handler.js +1 -2
  11. package/esm/traced-schema.js +25 -3
  12. package/esm/utils.js +7 -36
  13. package/package.json +2 -5
  14. package/typings/create.d.cts +5 -1
  15. package/typings/create.d.ts +5 -1
  16. package/typings/index.d.cts +1 -3
  17. package/typings/index.d.ts +1 -3
  18. package/typings/orchestrator.d.cts +11 -4
  19. package/typings/orchestrator.d.ts +11 -4
  20. package/typings/plugins/use-error-handler.d.cts +1 -2
  21. package/typings/plugins/use-error-handler.d.ts +1 -2
  22. package/typings/plugins/use-payload-formatter.d.cts +1 -2
  23. package/typings/plugins/use-payload-formatter.d.ts +1 -2
  24. package/typings/plugins/use-schema.d.cts +3 -4
  25. package/typings/plugins/use-schema.d.ts +3 -4
  26. package/typings/traced-schema.d.cts +1 -3
  27. package/typings/traced-schema.d.ts +1 -3
  28. package/typings/utils.d.cts +4 -8
  29. package/typings/utils.d.ts +4 -8
  30. package/cjs/plugins/use-immediate-introspection.js +0 -50
  31. package/cjs/plugins/use-masked-errors.js +0 -93
  32. package/cjs/plugins/use-timing.js +0 -138
  33. package/cjs/traced-orchestrator.js +0 -136
  34. package/esm/plugins/use-immediate-introspection.js +0 -46
  35. package/esm/plugins/use-masked-errors.js +0 -87
  36. package/esm/plugins/use-timing.js +0 -134
  37. package/esm/traced-orchestrator.js +0 -132
  38. package/typings/plugins/use-immediate-introspection.d.cts +0 -6
  39. package/typings/plugins/use-immediate-introspection.d.ts +0 -6
  40. package/typings/plugins/use-masked-errors.d.cts +0 -39
  41. package/typings/plugins/use-masked-errors.d.ts +0 -39
  42. package/typings/plugins/use-timing.d.cts +0 -21
  43. package/typings/plugins/use-timing.d.ts +0 -21
  44. package/typings/traced-orchestrator.d.cts +0 -7
  45. package/typings/traced-orchestrator.d.ts +0 -7
package/cjs/create.js CHANGED
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.envelop = void 0;
4
4
  const enable_if_js_1 = require("./enable-if.js");
5
5
  const orchestrator_js_1 = require("./orchestrator.js");
6
- const traced_orchestrator_js_1 = require("./traced-orchestrator.js");
7
6
  function envelop(options) {
8
7
  const plugins = options.plugins.filter(enable_if_js_1.isPluginEnabled);
9
- let orchestrator = (0, orchestrator_js_1.createEnvelopOrchestrator)(plugins);
10
- if (options.enableInternalTracing) {
11
- orchestrator = (0, traced_orchestrator_js_1.traceOrchestrator)(orchestrator);
12
- }
8
+ const orchestrator = (0, orchestrator_js_1.createEnvelopOrchestrator)({
9
+ plugins,
10
+ parse: options.parse,
11
+ execute: options.execute,
12
+ validate: options.validate,
13
+ subscribe: options.subscribe,
14
+ });
13
15
  const getEnveloped = (initialContext = {}) => {
14
16
  const typedOrchestrator = orchestrator;
15
17
  typedOrchestrator.init(initialContext);
package/cjs/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolversHooksSymbol = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("@envelop/types"), exports);
5
6
  tslib_1.__exportStar(require("./create.js"), exports);
6
7
  tslib_1.__exportStar(require("./utils.js"), exports);
7
8
  tslib_1.__exportStar(require("./plugins/use-envelop.js"), exports);
8
9
  tslib_1.__exportStar(require("./plugins/use-logger.js"), exports);
9
- tslib_1.__exportStar(require("./plugins/use-timing.js"), exports);
10
10
  tslib_1.__exportStar(require("./plugins/use-schema.js"), exports);
11
11
  tslib_1.__exportStar(require("./plugins/use-error-handler.js"), exports);
12
12
  tslib_1.__exportStar(require("./plugins/use-extend-context.js"), exports);
13
13
  tslib_1.__exportStar(require("./plugins/use-payload-formatter.js"), exports);
14
- tslib_1.__exportStar(require("./plugins/use-masked-errors.js"), exports);
15
- tslib_1.__exportStar(require("./plugins/use-immediate-introspection.js"), exports);
16
14
  tslib_1.__exportStar(require("./enable-if.js"), exports);
15
+ var traced_schema_js_1 = require("./traced-schema.js");
16
+ Object.defineProperty(exports, "resolversHooksSymbol", { enumerable: true, get: function () { return traced_schema_js_1.resolversHooksSymbol; } });
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createEnvelopOrchestrator = void 0;
4
- const graphql_1 = require("graphql");
5
4
  const traced_schema_js_1 = require("./traced-schema.js");
6
5
  const utils_js_1 = require("./utils.js");
7
- function createEnvelopOrchestrator(plugins) {
6
+ function createEnvelopOrchestrator({ plugins, parse, execute, subscribe, validate, }) {
8
7
  let schema = null;
9
8
  let initDone = false;
10
9
  const onResolversHandlers = [];
@@ -82,7 +81,7 @@ function createEnvelopOrchestrator(plugins) {
82
81
  const customParse = beforeCallbacks.parse.length
83
82
  ? initialContext => (source, parseOptions) => {
84
83
  let result = null;
85
- let parseFn = graphql_1.parse;
84
+ let parseFn = parse;
86
85
  const context = initialContext;
87
86
  const afterCalls = [];
88
87
  for (const onParse of beforeCallbacks.parse) {
@@ -130,11 +129,11 @@ function createEnvelopOrchestrator(plugins) {
130
129
  }
131
130
  return result;
132
131
  }
133
- : () => graphql_1.parse;
132
+ : () => parse;
134
133
  const customValidate = beforeCallbacks.validate.length
135
134
  ? initialContext => (schema, documentAST, rules, typeInfo, validationOptions) => {
136
135
  let actualRules = rules ? [...rules] : undefined;
137
- let validateFn = graphql_1.validate;
136
+ let validateFn = validate;
138
137
  let result = null;
139
138
  const context = initialContext;
140
139
  const afterCalls = [];
@@ -154,7 +153,10 @@ function createEnvelopOrchestrator(plugins) {
154
153
  validateFn,
155
154
  addValidationRule: rule => {
156
155
  if (!actualRules) {
157
- actualRules = [...graphql_1.specifiedRules];
156
+ // Ideally we should provide default validation rules here.
157
+ // eslint-disable-next-line no-console
158
+ console.warn('No default validation rules provided.');
159
+ actualRules = [];
158
160
  }
159
161
  actualRules.push(rule);
160
162
  },
@@ -170,6 +172,9 @@ function createEnvelopOrchestrator(plugins) {
170
172
  if (!result) {
171
173
  result = validateFn(schema, documentAST, actualRules, typeInfo, validationOptions);
172
174
  }
175
+ if (!result) {
176
+ return;
177
+ }
173
178
  const valid = result.length === 0;
174
179
  for (const afterCb of afterCalls) {
175
180
  afterCb({
@@ -186,7 +191,7 @@ function createEnvelopOrchestrator(plugins) {
186
191
  }
187
192
  return result;
188
193
  }
189
- : () => graphql_1.validate;
194
+ : () => validate;
190
195
  const customContextFactory = beforeCallbacks.context
191
196
  .length
192
197
  ? initialContext => async (orchestratorCtx) => {
@@ -240,7 +245,7 @@ function createEnvelopOrchestrator(plugins) {
240
245
  const useCustomSubscribe = beforeCallbacks.subscribe.length || onResolversHandlers.length;
241
246
  const customSubscribe = useCustomSubscribe
242
247
  ? (0, utils_js_1.makeSubscribe)(async (args) => {
243
- let subscribeFn = graphql_1.subscribe;
248
+ let subscribeFn = subscribe;
244
249
  const afterCalls = [];
245
250
  const subscribeErrorHandlers = [];
246
251
  let context = args.contextValue || {};
@@ -282,6 +287,9 @@ function createEnvelopOrchestrator(plugins) {
282
287
  // Can be removed once we drop support for GraphQL.js 15
283
288
  });
284
289
  }
290
+ if (!result) {
291
+ return;
292
+ }
285
293
  const onNextHandler = [];
286
294
  const onEndHandler = [];
287
295
  for (const afterCb of afterCalls) {
@@ -336,11 +344,11 @@ function createEnvelopOrchestrator(plugins) {
336
344
  }
337
345
  return result;
338
346
  })
339
- : (0, utils_js_1.makeSubscribe)(graphql_1.subscribe);
347
+ : (0, utils_js_1.makeSubscribe)(subscribe);
340
348
  const useCustomExecute = beforeCallbacks.execute.length || onResolversHandlers.length;
341
349
  const customExecute = useCustomExecute
342
350
  ? (0, utils_js_1.makeExecute)(async (args) => {
343
- let executeFn = graphql_1.execute;
351
+ let executeFn = execute;
344
352
  let result;
345
353
  const afterCalls = [];
346
354
  let context = args.contextValue || {};
@@ -366,7 +374,7 @@ function createEnvelopOrchestrator(plugins) {
366
374
  },
367
375
  args: args,
368
376
  });
369
- if (after === null || after === void 0 ? void 0 : after.onExecuteDone) {
377
+ if (after?.onExecuteDone) {
370
378
  afterCalls.push(after.onExecuteDone);
371
379
  }
372
380
  if (result !== undefined) {
@@ -424,7 +432,7 @@ function createEnvelopOrchestrator(plugins) {
424
432
  }
425
433
  return result;
426
434
  })
427
- : (0, utils_js_1.makeExecute)(graphql_1.execute);
435
+ : (0, utils_js_1.makeExecute)(execute);
428
436
  initDone = true;
429
437
  // This is done in order to trigger the first schema available, to allow plugins that needs the schema
430
438
  // eagerly to have it.
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useErrorHandler = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
5
  const makeHandleResult = (errorHandler) => ({ result, args }) => {
6
- var _a;
7
- if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
6
+ if (result.errors?.length) {
8
7
  errorHandler(result.errors, args);
9
8
  }
10
9
  };
@@ -1,21 +1,43 @@
1
1
  "use strict";
2
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');
3
+ exports.prepareTracedSchema = exports.resolversHooksSymbol = void 0;
6
4
  exports.resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
5
+ const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
6
+ function isObjectLike(value) {
7
+ return typeof value === 'object' && value !== null;
8
+ }
9
+ const isIntrospectionType = (type) => {
10
+ return type?.name?.startsWith('__');
11
+ };
12
+ /**
13
+ * This isn't the best but will get the job done
14
+ */
15
+ const isObjectType = (type) => {
16
+ if (isObjectLike(type) && '_interfaces' in type) {
17
+ return true;
18
+ }
19
+ return false;
20
+ };
21
+ // Note: in future we might have to drop this if there is some implementation which wildly differs
7
22
  function prepareTracedSchema(schema) {
8
- if (!schema || schema[exports.trackedSchemaSymbol]) {
23
+ if (!schema || schema[trackedSchemaSymbol]) {
9
24
  return;
10
25
  }
11
- schema[exports.trackedSchemaSymbol] = true;
26
+ schema[trackedSchemaSymbol] = true;
12
27
  const entries = Object.values(schema.getTypeMap());
13
28
  for (const type of entries) {
14
- if (!(0, graphql_1.isIntrospectionType)(type) && (0, graphql_1.isObjectType)(type)) {
29
+ if (!isIntrospectionType(type) && isObjectType(type)) {
30
+ // @ts-expect-error - we know this is an object type
15
31
  const fields = Object.values(type.getFields());
16
32
  for (const field of fields) {
17
- let resolverFn = (field.resolve || graphql_1.defaultFieldResolver);
33
+ // @ts-expect-error - we hope there is a resolve field
34
+ const existingResolver = field.resolve;
35
+ // We are not going to wrap any default resolvers
36
+ if (!existingResolver)
37
+ continue;
38
+ // @ts-expect-error - we know this is a resolver fn
18
39
  field.resolve = async (root, args, context, info) => {
40
+ let resolverFn = existingResolver;
19
41
  if (context && context[exports.resolversHooksSymbol]) {
20
42
  const hooks = context[exports.resolversHooksSymbol];
21
43
  const afterCalls = [];
package/cjs/utils.js CHANGED
@@ -1,32 +1,7 @@
1
1
  "use strict";
2
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");
3
+ exports.errorAsyncIterator = exports.finalAsyncIterator = exports.handleStreamOrSingleExecutionResult = exports.isAsyncIterable = exports.makeExecute = exports.mapAsyncIterator = exports.makeSubscribe = exports.isIntrospectionOperationString = exports.envelopIsIntrospectionSymbol = void 0;
5
4
  exports.envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
6
- function isOperationDefinition(def) {
7
- return def.kind === graphql_1.Kind.OPERATION_DEFINITION;
8
- }
9
- exports.isOperationDefinition = isOperationDefinition;
10
- function isIntrospectionOperation(operation) {
11
- return isIntrospectionDocument({
12
- kind: graphql_1.Kind.DOCUMENT,
13
- definitions: [operation],
14
- });
15
- }
16
- exports.isIntrospectionOperation = isIntrospectionOperation;
17
- function isIntrospectionDocument(document) {
18
- let isIntrospectionOperation = false;
19
- (0, graphql_1.visit)(document, {
20
- Field: node => {
21
- if (node.name.value === '__schema' || node.name.value === '__type') {
22
- isIntrospectionOperation = true;
23
- return graphql_1.BREAK;
24
- }
25
- },
26
- });
27
- return isIntrospectionOperation;
28
- }
29
- exports.isIntrospectionDocument = isIntrospectionDocument;
30
5
  function isIntrospectionOperationString(operation) {
31
6
  return (typeof operation === 'string' ? operation : operation.body).indexOf('__schema') !== -1;
32
7
  }
@@ -53,7 +28,6 @@ exports.makeSubscribe = makeSubscribe;
53
28
  function mapAsyncIterator(source, mapper) {
54
29
  const iterator = source[Symbol.asyncIterator]();
55
30
  async function mapResult(result) {
56
- var _a;
57
31
  if (result.done) {
58
32
  return result;
59
33
  }
@@ -62,7 +36,7 @@ function mapAsyncIterator(source, mapper) {
62
36
  }
63
37
  catch (error) {
64
38
  try {
65
- await ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
39
+ await iterator.return?.();
66
40
  }
67
41
  catch (_error) {
68
42
  /* ignore error */
@@ -78,13 +52,11 @@ function mapAsyncIterator(source, mapper) {
78
52
  return await mapResult(await iterator.next());
79
53
  },
80
54
  async return() {
81
- var _a;
82
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
55
+ const promise = iterator.return?.();
83
56
  return promise ? await mapResult(await promise) : { value: undefined, done: true };
84
57
  },
85
58
  async throw(error) {
86
- var _a;
87
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
59
+ const promise = iterator.throw?.();
88
60
  if (promise) {
89
61
  return await mapResult(await promise);
90
62
  }
@@ -162,8 +134,7 @@ function finalAsyncIterator(source, onFinal) {
162
134
  return result;
163
135
  },
164
136
  async return() {
165
- var _a;
166
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
137
+ const promise = iterator.return?.();
167
138
  if (isDone === false) {
168
139
  isDone = true;
169
140
  onFinal();
@@ -171,8 +142,7 @@ function finalAsyncIterator(source, onFinal) {
171
142
  return promise ? await promise : { done: true, value: undefined };
172
143
  },
173
144
  async throw(error) {
174
- var _a;
175
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
145
+ const promise = iterator.throw?.();
176
146
  if (promise) {
177
147
  return await promise;
178
148
  }
@@ -200,13 +170,11 @@ function errorAsyncIterator(source, onError) {
200
170
  }
201
171
  },
202
172
  async return() {
203
- var _a;
204
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
173
+ const promise = iterator.return?.();
205
174
  return promise ? await promise : { done: true, value: undefined };
206
175
  },
207
176
  async throw(error) {
208
- var _a;
209
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
177
+ const promise = iterator.throw?.();
210
178
  if (promise) {
211
179
  return await promise;
212
180
  }
package/esm/create.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { isPluginEnabled } from './enable-if.js';
2
2
  import { createEnvelopOrchestrator } from './orchestrator.js';
3
- import { traceOrchestrator } from './traced-orchestrator.js';
4
3
  export function envelop(options) {
5
4
  const plugins = options.plugins.filter(isPluginEnabled);
6
- let orchestrator = createEnvelopOrchestrator(plugins);
7
- if (options.enableInternalTracing) {
8
- orchestrator = traceOrchestrator(orchestrator);
9
- }
5
+ const orchestrator = createEnvelopOrchestrator({
6
+ plugins,
7
+ parse: options.parse,
8
+ execute: options.execute,
9
+ validate: options.validate,
10
+ subscribe: options.subscribe,
11
+ });
10
12
  const getEnveloped = (initialContext = {}) => {
11
13
  const typedOrchestrator = orchestrator;
12
14
  typedOrchestrator.init(initialContext);
package/esm/index.js CHANGED
@@ -3,11 +3,9 @@ export * from './create.js';
3
3
  export * from './utils.js';
4
4
  export * from './plugins/use-envelop.js';
5
5
  export * from './plugins/use-logger.js';
6
- export * from './plugins/use-timing.js';
7
6
  export * from './plugins/use-schema.js';
8
7
  export * from './plugins/use-error-handler.js';
9
8
  export * from './plugins/use-extend-context.js';
10
9
  export * from './plugins/use-payload-formatter.js';
11
- export * from './plugins/use-masked-errors.js';
12
- export * from './plugins/use-immediate-introspection.js';
13
10
  export * from './enable-if.js';
11
+ export { resolversHooksSymbol } from './traced-schema.js';
@@ -1,7 +1,6 @@
1
- import { execute, parse, specifiedRules, subscribe, validate, } from 'graphql';
2
1
  import { prepareTracedSchema, resolversHooksSymbol } from './traced-schema.js';
3
2
  import { errorAsyncIterator, finalAsyncIterator, makeExecute, makeSubscribe, mapAsyncIterator, isAsyncIterable, } from './utils.js';
4
- export function createEnvelopOrchestrator(plugins) {
3
+ export function createEnvelopOrchestrator({ plugins, parse, execute, subscribe, validate, }) {
5
4
  let schema = null;
6
5
  let initDone = false;
7
6
  const onResolversHandlers = [];
@@ -151,7 +150,10 @@ export function createEnvelopOrchestrator(plugins) {
151
150
  validateFn,
152
151
  addValidationRule: rule => {
153
152
  if (!actualRules) {
154
- actualRules = [...specifiedRules];
153
+ // Ideally we should provide default validation rules here.
154
+ // eslint-disable-next-line no-console
155
+ console.warn('No default validation rules provided.');
156
+ actualRules = [];
155
157
  }
156
158
  actualRules.push(rule);
157
159
  },
@@ -167,6 +169,9 @@ export function createEnvelopOrchestrator(plugins) {
167
169
  if (!result) {
168
170
  result = validateFn(schema, documentAST, actualRules, typeInfo, validationOptions);
169
171
  }
172
+ if (!result) {
173
+ return;
174
+ }
170
175
  const valid = result.length === 0;
171
176
  for (const afterCb of afterCalls) {
172
177
  afterCb({
@@ -279,6 +284,9 @@ export function createEnvelopOrchestrator(plugins) {
279
284
  // Can be removed once we drop support for GraphQL.js 15
280
285
  });
281
286
  }
287
+ if (!result) {
288
+ return;
289
+ }
282
290
  const onNextHandler = [];
283
291
  const onEndHandler = [];
284
292
  for (const afterCb of afterCalls) {
@@ -363,7 +371,7 @@ export function createEnvelopOrchestrator(plugins) {
363
371
  },
364
372
  args: args,
365
373
  });
366
- if (after === null || after === void 0 ? void 0 : after.onExecuteDone) {
374
+ if (after?.onExecuteDone) {
367
375
  afterCalls.push(after.onExecuteDone);
368
376
  }
369
377
  if (result !== undefined) {
@@ -1,7 +1,6 @@
1
1
  import { handleStreamOrSingleExecutionResult } from '../utils.js';
2
2
  const makeHandleResult = (errorHandler) => ({ result, args }) => {
3
- var _a;
4
- if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
3
+ if (result.errors?.length) {
5
4
  errorHandler(result.errors, args);
6
5
  }
7
6
  };
@@ -1,6 +1,21 @@
1
- import { defaultFieldResolver, isIntrospectionType, isObjectType } from 'graphql';
2
- export const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
3
1
  export const resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
2
+ const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
3
+ function isObjectLike(value) {
4
+ return typeof value === 'object' && value !== null;
5
+ }
6
+ const isIntrospectionType = (type) => {
7
+ return type?.name?.startsWith('__');
8
+ };
9
+ /**
10
+ * This isn't the best but will get the job done
11
+ */
12
+ const isObjectType = (type) => {
13
+ if (isObjectLike(type) && '_interfaces' in type) {
14
+ return true;
15
+ }
16
+ return false;
17
+ };
18
+ // Note: in future we might have to drop this if there is some implementation which wildly differs
4
19
  export function prepareTracedSchema(schema) {
5
20
  if (!schema || schema[trackedSchemaSymbol]) {
6
21
  return;
@@ -9,10 +24,17 @@ export function prepareTracedSchema(schema) {
9
24
  const entries = Object.values(schema.getTypeMap());
10
25
  for (const type of entries) {
11
26
  if (!isIntrospectionType(type) && isObjectType(type)) {
27
+ // @ts-expect-error - we know this is an object type
12
28
  const fields = Object.values(type.getFields());
13
29
  for (const field of fields) {
14
- let resolverFn = (field.resolve || defaultFieldResolver);
30
+ // @ts-expect-error - we hope there is a resolve field
31
+ const existingResolver = field.resolve;
32
+ // We are not going to wrap any default resolvers
33
+ if (!existingResolver)
34
+ continue;
35
+ // @ts-expect-error - we know this is a resolver fn
15
36
  field.resolve = async (root, args, context, info) => {
37
+ let resolverFn = existingResolver;
16
38
  if (context && context[resolversHooksSymbol]) {
17
39
  const hooks = context[resolversHooksSymbol];
18
40
  const afterCalls = [];
package/esm/utils.js CHANGED
@@ -1,26 +1,4 @@
1
- import { Kind, visit, BREAK, } from 'graphql';
2
1
  export const envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
3
- export function isOperationDefinition(def) {
4
- return def.kind === Kind.OPERATION_DEFINITION;
5
- }
6
- export function isIntrospectionOperation(operation) {
7
- return isIntrospectionDocument({
8
- kind: Kind.DOCUMENT,
9
- definitions: [operation],
10
- });
11
- }
12
- export function isIntrospectionDocument(document) {
13
- let isIntrospectionOperation = false;
14
- visit(document, {
15
- Field: node => {
16
- if (node.name.value === '__schema' || node.name.value === '__type') {
17
- isIntrospectionOperation = true;
18
- return BREAK;
19
- }
20
- },
21
- });
22
- return isIntrospectionOperation;
23
- }
24
2
  export function isIntrospectionOperationString(operation) {
25
3
  return (typeof operation === 'string' ? operation : operation.body).indexOf('__schema') !== -1;
26
4
  }
@@ -45,7 +23,6 @@ export const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getS
45
23
  export function mapAsyncIterator(source, mapper) {
46
24
  const iterator = source[Symbol.asyncIterator]();
47
25
  async function mapResult(result) {
48
- var _a;
49
26
  if (result.done) {
50
27
  return result;
51
28
  }
@@ -54,7 +31,7 @@ export function mapAsyncIterator(source, mapper) {
54
31
  }
55
32
  catch (error) {
56
33
  try {
57
- await ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
34
+ await iterator.return?.();
58
35
  }
59
36
  catch (_error) {
60
37
  /* ignore error */
@@ -70,13 +47,11 @@ export function mapAsyncIterator(source, mapper) {
70
47
  return await mapResult(await iterator.next());
71
48
  },
72
49
  async return() {
73
- var _a;
74
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
50
+ const promise = iterator.return?.();
75
51
  return promise ? await mapResult(await promise) : { value: undefined, done: true };
76
52
  },
77
53
  async throw(error) {
78
- var _a;
79
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
54
+ const promise = iterator.throw?.();
80
55
  if (promise) {
81
56
  return await mapResult(await promise);
82
57
  }
@@ -150,8 +125,7 @@ export function finalAsyncIterator(source, onFinal) {
150
125
  return result;
151
126
  },
152
127
  async return() {
153
- var _a;
154
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
128
+ const promise = iterator.return?.();
155
129
  if (isDone === false) {
156
130
  isDone = true;
157
131
  onFinal();
@@ -159,8 +133,7 @@ export function finalAsyncIterator(source, onFinal) {
159
133
  return promise ? await promise : { done: true, value: undefined };
160
134
  },
161
135
  async throw(error) {
162
- var _a;
163
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
136
+ const promise = iterator.throw?.();
164
137
  if (promise) {
165
138
  return await promise;
166
139
  }
@@ -187,13 +160,11 @@ export function errorAsyncIterator(source, onError) {
187
160
  }
188
161
  },
189
162
  async return() {
190
- var _a;
191
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
163
+ const promise = iterator.return?.();
192
164
  return promise ? await promise : { done: true, value: undefined };
193
165
  },
194
166
  async throw(error) {
195
- var _a;
196
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
167
+ const promise = iterator.throw?.();
197
168
  if (promise) {
198
169
  return await promise;
199
170
  }
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.6.0",
3
+ "version": "2.6.1-alpha-20220901205925-b1fd44a9",
4
4
  "sideEffects": false,
5
- "peerDependencies": {
6
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
- },
8
5
  "dependencies": {
9
- "@envelop/types": "2.4.0",
6
+ "@envelop/types": "2.4.1-alpha-20220901205925-b1fd44a9",
10
7
  "tslib": "2.4.0"
11
8
  },
12
9
  "repository": {
@@ -1,6 +1,10 @@
1
- import { GetEnvelopedFn, ComposeContext, Plugin } from '@envelop/types';
1
+ import { GetEnvelopedFn, ComposeContext, Plugin, ExecuteFunction, SubscribeFunction, ParseFunction, ValidateFunction } from '@envelop/types';
2
2
  import { PluginOrDisabledPlugin } from './enable-if.cjs';
3
3
  export declare function envelop<PluginsType extends Plugin<any>[]>(options: {
4
4
  plugins: Array<PluginOrDisabledPlugin>;
5
5
  enableInternalTracing?: boolean;
6
+ parse: ParseFunction;
7
+ execute: ExecuteFunction;
8
+ validate: ValidateFunction;
9
+ subscribe: SubscribeFunction;
6
10
  }): GetEnvelopedFn<ComposeContext<PluginsType>>;
@@ -1,6 +1,10 @@
1
- import { GetEnvelopedFn, ComposeContext, Plugin } from '@envelop/types';
1
+ import { GetEnvelopedFn, ComposeContext, Plugin, ExecuteFunction, SubscribeFunction, ParseFunction, ValidateFunction } from '@envelop/types';
2
2
  import { PluginOrDisabledPlugin } from './enable-if.js';
3
3
  export declare function envelop<PluginsType extends Plugin<any>[]>(options: {
4
4
  plugins: Array<PluginOrDisabledPlugin>;
5
5
  enableInternalTracing?: boolean;
6
+ parse: ParseFunction;
7
+ execute: ExecuteFunction;
8
+ validate: ValidateFunction;
9
+ subscribe: SubscribeFunction;
6
10
  }): GetEnvelopedFn<ComposeContext<PluginsType>>;
@@ -3,11 +3,9 @@ export * from './create.cjs';
3
3
  export * from './utils.cjs';
4
4
  export * from './plugins/use-envelop.cjs';
5
5
  export * from './plugins/use-logger.cjs';
6
- export * from './plugins/use-timing.cjs';
7
6
  export * from './plugins/use-schema.cjs';
8
7
  export * from './plugins/use-error-handler.cjs';
9
8
  export * from './plugins/use-extend-context.cjs';
10
9
  export * from './plugins/use-payload-formatter.cjs';
11
- export * from './plugins/use-masked-errors.cjs';
12
- export * from './plugins/use-immediate-introspection.cjs';
13
10
  export * from './enable-if.cjs';
11
+ export { resolversHooksSymbol } from './traced-schema.cjs';
@@ -3,11 +3,9 @@ export * from './create.js';
3
3
  export * from './utils.js';
4
4
  export * from './plugins/use-envelop.js';
5
5
  export * from './plugins/use-logger.js';
6
- export * from './plugins/use-timing.js';
7
6
  export * from './plugins/use-schema.js';
8
7
  export * from './plugins/use-error-handler.js';
9
8
  export * from './plugins/use-extend-context.js';
10
9
  export * from './plugins/use-payload-formatter.js';
11
- export * from './plugins/use-masked-errors.js';
12
- export * from './plugins/use-immediate-introspection.js';
13
10
  export * from './enable-if.js';
11
+ export { resolversHooksSymbol } from './traced-schema.js';
@@ -1,5 +1,4 @@
1
- import { ArbitraryObject, EnvelopContextFnWrapper, GetEnvelopedFn, Plugin, DefaultContext, Maybe } from '@envelop/types';
2
- import { GraphQLSchema } from 'graphql';
1
+ import { ArbitraryObject, EnvelopContextFnWrapper, GetEnvelopedFn, Plugin, SubscribeFunction, ExecuteFunction, DefaultContext, Maybe, ParseFunction, ValidateFunction } from '@envelop/types';
3
2
  export declare type EnvelopOrchestrator<InitialContext extends ArbitraryObject = ArbitraryObject, PluginsContext extends ArbitraryObject = ArbitraryObject> = {
4
3
  init: (initialContext?: Maybe<InitialContext>) => void;
5
4
  parse: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['parse'], InitialContext>;
@@ -7,6 +6,14 @@ export declare type EnvelopOrchestrator<InitialContext extends ArbitraryObject =
7
6
  execute: ReturnType<GetEnvelopedFn<PluginsContext>>['execute'];
8
7
  subscribe: ReturnType<GetEnvelopedFn<PluginsContext>>['subscribe'];
9
8
  contextFactory: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['contextFactory'], PluginsContext>;
10
- getCurrentSchema: () => Maybe<GraphQLSchema>;
9
+ getCurrentSchema: () => Maybe<any>;
11
10
  };
12
- export declare function createEnvelopOrchestrator<PluginsContext extends DefaultContext>(plugins: Plugin[]): EnvelopOrchestrator<any, PluginsContext>;
11
+ declare type EnvelopOrchestratorOptions = {
12
+ plugins: Plugin[];
13
+ parse: ParseFunction;
14
+ execute: ExecuteFunction;
15
+ subscribe: SubscribeFunction;
16
+ validate: ValidateFunction;
17
+ };
18
+ export declare function createEnvelopOrchestrator<PluginsContext extends DefaultContext>({ plugins, parse, execute, subscribe, validate, }: EnvelopOrchestratorOptions): EnvelopOrchestrator<any, PluginsContext>;
19
+ export {};