@graphql-tools/utils 6.0.10-alpha-19feca2.0 → 6.0.10

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/errors.d.ts CHANGED
@@ -3,10 +3,5 @@ export declare const ERROR_SYMBOL: unique symbol;
3
3
  export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>): GraphQLError;
4
4
  export declare function slicedError(originalError: GraphQLError): GraphQLError;
5
5
  export declare function getErrorsByPathSegment(errors: ReadonlyArray<GraphQLError>): Record<string, Array<GraphQLError>>;
6
- export declare class CombinedError extends GraphQLError {
7
- errors: ReadonlyArray<Error>;
8
- constructor(errors: ReadonlyArray<Error>);
9
- [Symbol.iterator](): IterableIterator<Error>;
10
- }
11
6
  export declare function setErrors(result: any, errors: Array<GraphQLError>): void;
12
7
  export declare function getErrors(result: any, pathSegment: string): Array<GraphQLError>;
package/index.cjs.js CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
5
7
  const graphql = require('graphql');
8
+ const AggregateError = _interopDefault(require('aggregate-error'));
6
9
  const camelCase = require('camel-case');
7
10
  const utils = require('@graphql-tools/utils');
8
11
 
@@ -461,54 +464,6 @@ function getSchemaDefinition(schema) {
461
464
  }
462
465
  }
463
466
 
464
- const ERROR_SYMBOL = Symbol('subschemaErrors');
465
- function relocatedError(originalError, path) {
466
- return new graphql.GraphQLError(originalError.message, originalError.nodes, originalError.source, originalError.positions, path === null ? undefined : path === undefined ? originalError.path : path, originalError.originalError, originalError.extensions);
467
- }
468
- function slicedError(originalError) {
469
- return relocatedError(originalError, originalError.path != null ? originalError.path.slice(1) : undefined);
470
- }
471
- function getErrorsByPathSegment(errors) {
472
- const record = Object.create(null);
473
- errors.forEach(error => {
474
- if (!error.path || error.path.length < 2) {
475
- return;
476
- }
477
- const pathSegment = error.path[1];
478
- const current = pathSegment in record ? record[pathSegment] : [];
479
- current.push(slicedError(error));
480
- record[pathSegment] = current;
481
- });
482
- return record;
483
- }
484
- class CombinedError extends graphql.GraphQLError {
485
- constructor(errors) {
486
- const message = errors.map(error => error.message).join('\n');
487
- super(message, undefined, undefined, undefined, undefined, undefined, undefined);
488
- const actualErrors = errors.map((error) => error.originalError != null ? error.originalError : error);
489
- this.errors = actualErrors;
490
- }
491
- [Symbol.iterator]() {
492
- return this.errors[Symbol.iterator]();
493
- }
494
- }
495
- function setErrors(result, errors) {
496
- result[ERROR_SYMBOL] = errors;
497
- }
498
- function getErrors(result, pathSegment) {
499
- const errors = result != null ? result[ERROR_SYMBOL] : result;
500
- if (!Array.isArray(errors)) {
501
- return null;
502
- }
503
- const fieldErrors = [];
504
- for (const error of errors) {
505
- if (!error.path || error.path[0] === pathSegment) {
506
- fieldErrors.push(error);
507
- }
508
- }
509
- return fieldErrors;
510
- }
511
-
512
467
  const DEFAULT_EFFECTIVE_RULES = createDefaultRules();
513
468
  async function validateGraphQlDocuments(schema, documentFiles, effectiveRules = DEFAULT_EFFECTIVE_RULES) {
514
469
  const allFragments = [];
@@ -559,7 +514,7 @@ function checkValidationErrors(loadDocumentErrors) {
559
514
  errors.push(error);
560
515
  }
561
516
  }
562
- throw new CombinedError(errors);
517
+ throw new AggregateError(errors);
563
518
  }
564
519
  }
565
520
  function createDefaultRules() {
@@ -3388,6 +3343,43 @@ function implementsAbstractType(schema, typeA, typeB) {
3388
3343
  return false;
3389
3344
  }
3390
3345
 
3346
+ const ERROR_SYMBOL = Symbol('subschemaErrors');
3347
+ function relocatedError(originalError, path) {
3348
+ return new graphql.GraphQLError(originalError.message, originalError.nodes, originalError.source, originalError.positions, path === null ? undefined : path === undefined ? originalError.path : path, originalError.originalError, originalError.extensions);
3349
+ }
3350
+ function slicedError(originalError) {
3351
+ return relocatedError(originalError, originalError.path != null ? originalError.path.slice(1) : undefined);
3352
+ }
3353
+ function getErrorsByPathSegment(errors) {
3354
+ const record = Object.create(null);
3355
+ errors.forEach(error => {
3356
+ if (!error.path || error.path.length < 2) {
3357
+ return;
3358
+ }
3359
+ const pathSegment = error.path[1];
3360
+ const current = pathSegment in record ? record[pathSegment] : [];
3361
+ current.push(slicedError(error));
3362
+ record[pathSegment] = current;
3363
+ });
3364
+ return record;
3365
+ }
3366
+ function setErrors(result, errors) {
3367
+ result[ERROR_SYMBOL] = errors;
3368
+ }
3369
+ function getErrors(result, pathSegment) {
3370
+ const errors = result != null ? result[ERROR_SYMBOL] : result;
3371
+ if (!Array.isArray(errors)) {
3372
+ return null;
3373
+ }
3374
+ const fieldErrors = [];
3375
+ for (const error of errors) {
3376
+ if (!error.path || error.path[0] === pathSegment) {
3377
+ fieldErrors.push(error);
3378
+ }
3379
+ }
3380
+ return fieldErrors;
3381
+ }
3382
+
3391
3383
  function inputFieldToFieldConfig(field) {
3392
3384
  return {
3393
3385
  description: field.description,
@@ -3494,7 +3486,6 @@ function observableToAsyncIterable(observable) {
3494
3486
  };
3495
3487
  }
3496
3488
 
3497
- exports.CombinedError = CombinedError;
3498
3489
  exports.ERROR_SYMBOL = ERROR_SYMBOL;
3499
3490
  exports.SchemaDirectiveVisitor = SchemaDirectiveVisitor;
3500
3491
  exports.SchemaVisitor = SchemaVisitor;