@envelop/core 2.5.0 → 2.5.1-alpha-20220824152235-afd061e6

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 (43) hide show
  1. package/cjs/create.js +7 -5
  2. package/cjs/index.js +3 -3
  3. package/cjs/orchestrator.js +24 -16
  4. package/cjs/utils.js +1 -27
  5. package/esm/create.js +7 -5
  6. package/esm/index.js +1 -3
  7. package/esm/orchestrator.js +13 -5
  8. package/esm/utils.js +0 -23
  9. package/package.json +2 -5
  10. package/typings/create.d.cts +5 -1
  11. package/typings/create.d.ts +5 -1
  12. package/typings/index.d.cts +1 -3
  13. package/typings/index.d.ts +1 -3
  14. package/typings/orchestrator.d.cts +12 -4
  15. package/typings/orchestrator.d.ts +12 -4
  16. package/typings/plugins/use-error-handler.d.cts +1 -2
  17. package/typings/plugins/use-error-handler.d.ts +1 -2
  18. package/typings/plugins/use-payload-formatter.d.cts +1 -2
  19. package/typings/plugins/use-payload-formatter.d.ts +1 -2
  20. package/typings/plugins/use-schema.d.cts +3 -4
  21. package/typings/plugins/use-schema.d.ts +3 -4
  22. package/typings/utils.d.cts +4 -8
  23. package/typings/utils.d.ts +4 -8
  24. package/cjs/plugins/use-immediate-introspection.js +0 -50
  25. package/cjs/plugins/use-masked-errors.js +0 -93
  26. package/cjs/plugins/use-timing.js +0 -138
  27. package/cjs/traced-orchestrator.js +0 -136
  28. package/cjs/traced-schema.js +0 -68
  29. package/esm/plugins/use-immediate-introspection.js +0 -46
  30. package/esm/plugins/use-masked-errors.js +0 -87
  31. package/esm/plugins/use-timing.js +0 -134
  32. package/esm/traced-orchestrator.js +0 -132
  33. package/esm/traced-schema.js +0 -64
  34. package/typings/plugins/use-immediate-introspection.d.cts +0 -6
  35. package/typings/plugins/use-immediate-introspection.d.ts +0 -6
  36. package/typings/plugins/use-masked-errors.d.cts +0 -39
  37. package/typings/plugins/use-masked-errors.d.ts +0 -39
  38. package/typings/plugins/use-timing.d.cts +0 -21
  39. package/typings/plugins/use-timing.d.ts +0 -21
  40. package/typings/traced-orchestrator.d.cts +0 -7
  41. package/typings/traced-orchestrator.d.ts +0 -7
  42. package/typings/traced-schema.d.cts +0 -4
  43. package/typings/traced-schema.d.ts +0 -4
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 orchestrator_js_1 = require("./orchestrator.js");
16
+ Object.defineProperty(exports, "resolversHooksSymbol", { enumerable: true, get: function () { return orchestrator_js_1.resolversHooksSymbol; } });
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
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");
3
+ exports.createEnvelopOrchestrator = exports.resolversHooksSymbol = void 0;
6
4
  const utils_js_1 = require("./utils.js");
7
- function createEnvelopOrchestrator(plugins) {
5
+ exports.resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
6
+ function createEnvelopOrchestrator({ plugins, parse, execute, subscribe, validate, }) {
8
7
  let schema = null;
9
8
  let initDone = false;
10
9
  const onResolversHandlers = [];
@@ -18,7 +17,7 @@ function createEnvelopOrchestrator(plugins) {
18
17
  // here not to call the same plugin that initiated the schema switch.
19
18
  const replaceSchema = (newSchema, ignorePluginIndex = -1) => {
20
19
  if (onResolversHandlers.length) {
21
- (0, traced_schema_js_1.prepareTracedSchema)(newSchema);
20
+ // prepareTracedSchema(newSchema);
22
21
  }
23
22
  schema = newSchema;
24
23
  if (initDone) {
@@ -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 || {};
@@ -272,7 +277,7 @@ function createEnvelopOrchestrator(plugins) {
272
277
  }
273
278
  }
274
279
  if (onResolversHandlers.length) {
275
- context[traced_schema_js_1.resolversHooksSymbol] = onResolversHandlers;
280
+ context[exports.resolversHooksSymbol] = onResolversHandlers;
276
281
  }
277
282
  if (result === undefined) {
278
283
  result = await subscribeFn({
@@ -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 || {};
@@ -374,7 +382,7 @@ function createEnvelopOrchestrator(plugins) {
374
382
  }
375
383
  }
376
384
  if (onResolversHandlers.length) {
377
- context[traced_schema_js_1.resolversHooksSymbol] = onResolversHandlers;
385
+ context[exports.resolversHooksSymbol] = onResolversHandlers;
378
386
  }
379
387
  if (result === undefined) {
380
388
  result = (await executeFn({
@@ -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.
package/cjs/utils.js CHANGED
@@ -1,33 +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
- if (operation.kind === 'OperationDefinition') {
12
- let hasIntrospectionField = false;
13
- (0, graphql_1.visit)(operation, {
14
- Field: node => {
15
- if (node.name.value === '__schema') {
16
- hasIntrospectionField = true;
17
- return graphql_1.BREAK;
18
- }
19
- },
20
- });
21
- return hasIntrospectionField;
22
- }
23
- return false;
24
- }
25
- exports.isIntrospectionOperation = isIntrospectionOperation;
26
- function isIntrospectionDocument(document) {
27
- const operations = document.definitions.filter(isOperationDefinition);
28
- return operations.some(op => isIntrospectionOperation(op));
29
- }
30
- exports.isIntrospectionDocument = isIntrospectionDocument;
31
5
  function isIntrospectionOperationString(operation) {
32
6
  return (typeof operation === 'string' ? operation : operation.body).indexOf('__schema') !== -1;
33
7
  }
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 './orchestrator.js';
@@ -1,7 +1,6 @@
1
- import { execute, parse, specifiedRules, subscribe, validate, } from 'graphql';
2
- import { prepareTracedSchema, resolversHooksSymbol } from './traced-schema.js';
3
1
  import { errorAsyncIterator, finalAsyncIterator, makeExecute, makeSubscribe, mapAsyncIterator, isAsyncIterable, } from './utils.js';
4
- export function createEnvelopOrchestrator(plugins) {
2
+ export const resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
3
+ export function createEnvelopOrchestrator({ plugins, parse, execute, subscribe, validate, }) {
5
4
  let schema = null;
6
5
  let initDone = false;
7
6
  const onResolversHandlers = [];
@@ -15,7 +14,7 @@ export function createEnvelopOrchestrator(plugins) {
15
14
  // here not to call the same plugin that initiated the schema switch.
16
15
  const replaceSchema = (newSchema, ignorePluginIndex = -1) => {
17
16
  if (onResolversHandlers.length) {
18
- prepareTracedSchema(newSchema);
17
+ // prepareTracedSchema(newSchema);
19
18
  }
20
19
  schema = newSchema;
21
20
  if (initDone) {
@@ -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) {
package/esm/utils.js CHANGED
@@ -1,27 +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
- if (operation.kind === 'OperationDefinition') {
8
- let hasIntrospectionField = false;
9
- visit(operation, {
10
- Field: node => {
11
- if (node.name.value === '__schema') {
12
- hasIntrospectionField = true;
13
- return BREAK;
14
- }
15
- },
16
- });
17
- return hasIntrospectionField;
18
- }
19
- return false;
20
- }
21
- export function isIntrospectionDocument(document) {
22
- const operations = document.definitions.filter(isOperationDefinition);
23
- return operations.some(op => isIntrospectionOperation(op));
24
- }
25
2
  export function isIntrospectionOperationString(operation) {
26
3
  return (typeof operation === 'string' ? operation : operation.body).indexOf('__schema') !== -1;
27
4
  }
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.5.0",
3
+ "version": "2.5.1-alpha-20220824152235-afd061e6",
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.3.1"
6
+ "@envelop/types": "2.3.2-alpha-20220824152235-afd061e6"
10
7
  },
11
8
  "repository": {
12
9
  "type": "git",
@@ -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 './orchestrator.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 './orchestrator.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,15 @@ 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 const resolversHooksSymbol: unique symbol;
19
+ export declare function createEnvelopOrchestrator<PluginsContext extends DefaultContext>({ plugins, parse, execute, subscribe, validate, }: EnvelopOrchestratorOptions): EnvelopOrchestrator<any, PluginsContext>;
20
+ export {};
@@ -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,15 @@ 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 const resolversHooksSymbol: unique symbol;
19
+ export declare function createEnvelopOrchestrator<PluginsContext extends DefaultContext>({ plugins, parse, execute, subscribe, validate, }: EnvelopOrchestratorOptions): EnvelopOrchestrator<any, PluginsContext>;
20
+ export {};
@@ -1,4 +1,3 @@
1
1
  import { Plugin, DefaultContext } from '@envelop/types';
2
- import { GraphQLError } from 'graphql';
3
- export declare type ErrorHandler = (errors: readonly GraphQLError[], context: Readonly<DefaultContext>) => void;
2
+ export declare type ErrorHandler = (errors: readonly Error[] | any[], context: Readonly<DefaultContext>) => void;
4
3
  export declare const useErrorHandler: <ContextType>(errorHandler: ErrorHandler) => Plugin<ContextType>;
@@ -1,4 +1,3 @@
1
1
  import { Plugin, DefaultContext } from '@envelop/types';
2
- import { GraphQLError } from 'graphql';
3
- export declare type ErrorHandler = (errors: readonly GraphQLError[], context: Readonly<DefaultContext>) => void;
2
+ export declare type ErrorHandler = (errors: readonly Error[] | any[], context: Readonly<DefaultContext>) => void;
4
3
  export declare const useErrorHandler: <ContextType>(errorHandler: ErrorHandler) => Plugin<ContextType>;
@@ -1,4 +1,3 @@
1
- import { Plugin, TypedExecutionArgs } from '@envelop/types';
2
- import { ExecutionResult } from 'graphql';
1
+ import { Plugin, TypedExecutionArgs, ExecutionResult } from '@envelop/types';
3
2
  export declare type FormatterFunction = (result: ExecutionResult<any, any>, args: TypedExecutionArgs<any>) => false | ExecutionResult<any, any>;
4
3
  export declare const usePayloadFormatter: (formatter: FormatterFunction) => Plugin;
@@ -1,4 +1,3 @@
1
- import { Plugin, TypedExecutionArgs } from '@envelop/types';
2
- import { ExecutionResult } from 'graphql';
1
+ import { Plugin, TypedExecutionArgs, ExecutionResult } from '@envelop/types';
3
2
  export declare type FormatterFunction = (result: ExecutionResult<any, any>, args: TypedExecutionArgs<any>) => false | ExecutionResult<any, any>;
4
3
  export declare const usePayloadFormatter: (formatter: FormatterFunction) => Plugin;
@@ -1,5 +1,4 @@
1
- import { GraphQLSchema } from 'graphql';
2
1
  import { DefaultContext, Maybe, Plugin } from '@envelop/types';
3
- export declare const useSchema: (schema: GraphQLSchema) => Plugin;
4
- export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => GraphQLSchema) => Plugin;
5
- export declare const useAsyncSchema: (schemaPromise: Promise<GraphQLSchema>) => Plugin;
2
+ export declare const useSchema: (schema: any) => Plugin;
3
+ export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => any) => Plugin;
4
+ export declare const useAsyncSchema: (schemaPromise: Promise<any>) => Plugin;
@@ -1,5 +1,4 @@
1
- import { GraphQLSchema } from 'graphql';
2
1
  import { DefaultContext, Maybe, Plugin } from '@envelop/types';
3
- export declare const useSchema: (schema: GraphQLSchema) => Plugin;
4
- export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => GraphQLSchema) => Plugin;
5
- export declare const useAsyncSchema: (schemaPromise: Promise<GraphQLSchema>) => Plugin;
2
+ export declare const useSchema: (schema: any) => Plugin;
3
+ export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => any) => Plugin;
4
+ export declare const useAsyncSchema: (schemaPromise: Promise<any>) => Plugin;
@@ -1,19 +1,15 @@
1
- import { ASTNode, DocumentNode, OperationDefinitionNode, Source, ExecutionResult, SubscriptionArgs, ExecutionArgs } from 'graphql';
2
- import { AsyncIterableIteratorOrValue, ExecuteFunction, SubscribeFunction, PromiseOrValue, DefaultContext, OnExecuteDoneEventPayload, OnExecuteDoneHookResult, OnExecuteDoneHookResultOnNextHook } from '@envelop/types';
1
+ import { AsyncIterableIteratorOrValue, ExecuteFunction, SubscribeFunction, PromiseOrValue, DefaultContext, OnExecuteDoneEventPayload, OnExecuteDoneHookResult, OnExecuteDoneHookResultOnNextHook, ExecutionArgs } from '@envelop/types';
3
2
  export declare const envelopIsIntrospectionSymbol: unique symbol;
4
- export declare function isOperationDefinition(def: ASTNode): def is OperationDefinitionNode;
5
- export declare function isIntrospectionOperation(operation: OperationDefinitionNode): boolean;
6
- export declare function isIntrospectionDocument(document: DocumentNode): boolean;
7
- export declare function isIntrospectionOperationString(operation: string | Source): boolean;
3
+ export declare function isIntrospectionOperationString(operation: string | any): boolean;
8
4
  /**
9
5
  * Utility function for making a subscribe function that handles polymorphic arguments.
10
6
  */
11
- export declare const makeSubscribe: (subscribeFn: (args: SubscriptionArgs) => PromiseOrValue<AsyncIterableIterator<ExecutionResult>>) => SubscribeFunction;
7
+ export declare const makeSubscribe: (subscribeFn: (args: ExecutionArgs) => any) => SubscribeFunction;
12
8
  export declare function mapAsyncIterator<T, O>(source: AsyncIterable<T>, mapper: (input: T) => Promise<O> | O): AsyncGenerator<O>;
13
9
  /**
14
10
  * Utility function for making a execute function that handles polymorphic arguments.
15
11
  */
16
- export declare const makeExecute: (executeFn: (args: ExecutionArgs) => PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>>) => ExecuteFunction;
12
+ export declare const makeExecute: (executeFn: (args: ExecutionArgs) => PromiseOrValue<AsyncIterableIteratorOrValue<any>>) => ExecuteFunction;
17
13
  /**
18
14
  * Returns true if the provided object implements the AsyncIterator protocol via
19
15
  * implementing a `Symbol.asyncIterator` method.
@@ -1,19 +1,15 @@
1
- import { ASTNode, DocumentNode, OperationDefinitionNode, Source, ExecutionResult, SubscriptionArgs, ExecutionArgs } from 'graphql';
2
- import { AsyncIterableIteratorOrValue, ExecuteFunction, SubscribeFunction, PromiseOrValue, DefaultContext, OnExecuteDoneEventPayload, OnExecuteDoneHookResult, OnExecuteDoneHookResultOnNextHook } from '@envelop/types';
1
+ import { AsyncIterableIteratorOrValue, ExecuteFunction, SubscribeFunction, PromiseOrValue, DefaultContext, OnExecuteDoneEventPayload, OnExecuteDoneHookResult, OnExecuteDoneHookResultOnNextHook, ExecutionArgs } from '@envelop/types';
3
2
  export declare const envelopIsIntrospectionSymbol: unique symbol;
4
- export declare function isOperationDefinition(def: ASTNode): def is OperationDefinitionNode;
5
- export declare function isIntrospectionOperation(operation: OperationDefinitionNode): boolean;
6
- export declare function isIntrospectionDocument(document: DocumentNode): boolean;
7
- export declare function isIntrospectionOperationString(operation: string | Source): boolean;
3
+ export declare function isIntrospectionOperationString(operation: string | any): boolean;
8
4
  /**
9
5
  * Utility function for making a subscribe function that handles polymorphic arguments.
10
6
  */
11
- export declare const makeSubscribe: (subscribeFn: (args: SubscriptionArgs) => PromiseOrValue<AsyncIterableIterator<ExecutionResult>>) => SubscribeFunction;
7
+ export declare const makeSubscribe: (subscribeFn: (args: ExecutionArgs) => any) => SubscribeFunction;
12
8
  export declare function mapAsyncIterator<T, O>(source: AsyncIterable<T>, mapper: (input: T) => Promise<O> | O): AsyncGenerator<O>;
13
9
  /**
14
10
  * Utility function for making a execute function that handles polymorphic arguments.
15
11
  */
16
- export declare const makeExecute: (executeFn: (args: ExecutionArgs) => PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>>) => ExecuteFunction;
12
+ export declare const makeExecute: (executeFn: (args: ExecutionArgs) => PromiseOrValue<AsyncIterableIteratorOrValue<any>>) => ExecuteFunction;
17
13
  /**
18
14
  * Returns true if the provided object implements the AsyncIterator protocol via
19
15
  * implementing a `Symbol.asyncIterator` method.
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useImmediateIntrospection = void 0;
4
- const graphql_1 = require("graphql");
5
- const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
6
- const rootQueryType = ctx.getSchema().getQueryType();
7
- const rootMutationType = ctx.getSchema().getMutationType();
8
- const rootSubscriptionType = ctx.getSchema().getSubscriptionType();
9
- return {
10
- Field(field) {
11
- const parentType = ctx.getParentType();
12
- const isQuery = parentType === rootQueryType;
13
- const isMutation = parentType === rootMutationType;
14
- const isSubscription = parentType === rootSubscriptionType;
15
- if ((isQuery && !field.name.value.startsWith('__')) || isMutation || isSubscription) {
16
- onNonIntrospectionField();
17
- return graphql_1.BREAK;
18
- }
19
- return undefined;
20
- },
21
- };
22
- };
23
- const fastIntroSpectionSymbol = Symbol('fastIntrospection');
24
- /**
25
- * In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
26
- * With this plugin any further context extensions will be skipped.
27
- */
28
- const useImmediateIntrospection = () => {
29
- return {
30
- onValidate({ addValidationRule }) {
31
- let isIntrospectionOnly = true;
32
- addValidationRule(OnNonIntrospectionFieldReachedValidationRule(() => {
33
- isIntrospectionOnly = false;
34
- }));
35
- return function afterValidate({ extendContext }) {
36
- if (isIntrospectionOnly) {
37
- extendContext({ [fastIntroSpectionSymbol]: true });
38
- }
39
- };
40
- },
41
- onContextBuilding({ context, breakContextBuilding }) {
42
- if (context[fastIntroSpectionSymbol]) {
43
- // hijack and skip all other context related stuff.
44
- // We dont need a context!
45
- breakContextBuilding();
46
- }
47
- },
48
- };
49
- };
50
- exports.useImmediateIntrospection = useImmediateIntrospection;