@apollo/federation-internals 2.1.0-alpha.0 → 2.1.0-alpha.1

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 (57) hide show
  1. package/dist/buildSchema.d.ts.map +1 -1
  2. package/dist/buildSchema.js +11 -10
  3. package/dist/buildSchema.js.map +1 -1
  4. package/dist/coreSpec.d.ts.map +1 -1
  5. package/dist/coreSpec.js +15 -42
  6. package/dist/coreSpec.js.map +1 -1
  7. package/dist/definitions.d.ts.map +1 -1
  8. package/dist/definitions.js +49 -98
  9. package/dist/definitions.js.map +1 -1
  10. package/dist/directiveAndTypeSpecification.js +14 -48
  11. package/dist/directiveAndTypeSpecification.js.map +1 -1
  12. package/dist/error.d.ts +19 -17
  13. package/dist/error.d.ts.map +1 -1
  14. package/dist/error.js +40 -7
  15. package/dist/error.js.map +1 -1
  16. package/dist/federation.d.ts.map +1 -1
  17. package/dist/federation.js +70 -123
  18. package/dist/federation.js.map +1 -1
  19. package/dist/inaccessibleSpec.js +43 -65
  20. package/dist/inaccessibleSpec.js.map +1 -1
  21. package/dist/operations.d.ts.map +1 -1
  22. package/dist/operations.js +5 -4
  23. package/dist/operations.js.map +1 -1
  24. package/dist/schemaUpgrader.js +2 -8
  25. package/dist/schemaUpgrader.js.map +1 -1
  26. package/dist/supergraphs.d.ts.map +1 -1
  27. package/dist/supergraphs.js +4 -4
  28. package/dist/supergraphs.js.map +1 -1
  29. package/dist/tagSpec.d.ts.map +1 -1
  30. package/dist/tagSpec.js +1 -3
  31. package/dist/tagSpec.js.map +1 -1
  32. package/dist/validate.d.ts.map +1 -1
  33. package/dist/validate.js +26 -22
  34. package/dist/validate.js.map +1 -1
  35. package/dist/validation/KnownTypeNamesInFederationRule.js +1 -1
  36. package/dist/validation/KnownTypeNamesInFederationRule.js.map +1 -1
  37. package/dist/values.d.ts.map +1 -1
  38. package/dist/values.js +19 -18
  39. package/dist/values.js.map +1 -1
  40. package/package.json +2 -2
  41. package/src/__tests__/subgraphValidation.test.ts +75 -0
  42. package/src/buildSchema.ts +11 -18
  43. package/src/coreSpec.ts +47 -43
  44. package/src/definitions.ts +64 -96
  45. package/src/directiveAndTypeSpecification.ts +50 -48
  46. package/src/error.ts +87 -41
  47. package/src/federation.ts +142 -131
  48. package/src/inaccessibleSpec.ts +207 -191
  49. package/src/operations.ts +5 -5
  50. package/src/schemaUpgrader.ts +8 -8
  51. package/src/supergraphs.ts +5 -4
  52. package/src/tagSpec.ts +2 -3
  53. package/src/validate.ts +60 -52
  54. package/src/validation/KnownTypeNamesInFederationRule.ts +1 -1
  55. package/src/values.ts +19 -18
  56. package/tsconfig.test.tsbuildinfo +1 -1
  57. package/tsconfig.tsbuildinfo +1 -1
@@ -256,7 +256,7 @@ function typeFromAST(schema, node) {
256
256
  default:
257
257
  const type = schema.type(node.name.value);
258
258
  if (!type) {
259
- throw new graphql_1.GraphQLError(`Unknown type "${node.name.value}"`, node);
259
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Unknown type "${node.name.value}"`, { nodes: node });
260
260
  }
261
261
  return type;
262
262
  }
@@ -365,9 +365,7 @@ class Element {
365
365
  onAttached() {
366
366
  }
367
367
  checkUpdate() {
368
- if (!this.isAttached()) {
369
- throw error(`Cannot modify detached element ${this}`);
370
- }
368
+ (0, utils_1.assert)(this.isAttached(), () => `Cannot modify detached element ${this}`);
371
369
  }
372
370
  }
373
371
  class Extension {
@@ -404,7 +402,7 @@ class SchemaElement extends Element {
404
402
  this.checkUpdate();
405
403
  const def = (_a = this.schema().directive(nameOrDef)) !== null && _a !== void 0 ? _a : this.schema().blueprint.onMissingDirectiveDefinition(this.schema(), nameOrDef, args);
406
404
  if (!def) {
407
- throw this.schema().blueprint.onGraphQLJSValidationError(this.schema(), new graphql_1.GraphQLError(`Unknown directive "@${nameOrDef}".`));
405
+ throw this.schema().blueprint.onGraphQLJSValidationError(this.schema(), error_2.ERRORS.INVALID_GRAPHQL.err(`Unknown directive "@${nameOrDef}".`));
408
406
  }
409
407
  if (Array.isArray(def)) {
410
408
  throw (0, exports.ErrGraphQLValidationFailed)(def);
@@ -444,26 +442,20 @@ class SchemaElement extends Element {
444
442
  this.removeTypeReference(type);
445
443
  }
446
444
  checkRemoval() {
447
- if (this.isElementBuiltIn() && !Schema.prototype['canModifyBuiltIn'].call(this.schema())) {
448
- throw error(`Cannot modify built-in ${this}`);
449
- }
445
+ (0, utils_1.assert)(!this.isElementBuiltIn() || Schema.prototype['canModifyBuiltIn'].call(this.schema()), () => `Cannot modify built-in ${this}`);
450
446
  }
451
447
  checkUpdate(addedElement) {
452
448
  super.checkUpdate();
453
449
  if (!Schema.prototype['canModifyBuiltIn'].call(this.schema())) {
454
450
  let thisElement = this;
455
451
  while (thisElement && thisElement instanceof SchemaElement) {
456
- if (thisElement.isElementBuiltIn()) {
457
- throw error(`Cannot modify built-in (or part of built-in) ${this}`);
458
- }
452
+ (0, utils_1.assert)(!thisElement.isElementBuiltIn(), () => `Cannot modify built-in (or part of built-in) ${this}`);
459
453
  thisElement = thisElement.parent;
460
454
  }
461
455
  }
462
456
  if (addedElement && addedElement.isAttached()) {
463
457
  const thatSchema = addedElement.schema();
464
- if (thatSchema && thatSchema != this.schema()) {
465
- throw error(`Cannot add element ${addedElement} to ${this} as it is attached to another schema`);
466
- }
458
+ (0, utils_1.assert)(!thatSchema || thatSchema === this.schema(), () => `Cannot add element ${addedElement} to ${this} as it is attached to another schema`);
467
459
  }
468
460
  }
469
461
  }
@@ -508,9 +500,7 @@ class BaseNamedType extends NamedSchemaElement {
508
500
  if (this._extensions.has(extension)) {
509
501
  return extension;
510
502
  }
511
- if (extension.extendedElement) {
512
- throw error(`Cannot add extension to type ${this}: it is already added to another type`);
513
- }
503
+ (0, utils_1.assert)(!extension.extendedElement, () => `Cannot add extension to type ${this}: it is already added to another type`);
514
504
  this._extensions.add(extension);
515
505
  Extension.prototype['setExtendedElement'].call(extension, this);
516
506
  this.onModification();
@@ -603,9 +593,6 @@ class NamedSchemaElementWithType extends NamedSchemaElement {
603
593
  }
604
594
  }
605
595
  exports.NamedSchemaElementWithType = NamedSchemaElementWithType;
606
- function error(message) {
607
- return new graphql_1.GraphQLError(message);
608
- }
609
596
  class BaseExtensionMember extends Element {
610
597
  ofExtension() {
611
598
  return this._extension;
@@ -616,9 +603,7 @@ class BaseExtensionMember extends Element {
616
603
  setOfExtension(extension) {
617
604
  var _a;
618
605
  this.checkUpdate();
619
- if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
620
- throw error(`Cannot set object as part of the provided extension: it is not an extension of parent ${this.parent}`);
621
- }
606
+ (0, utils_1.assert)(!extension || ((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension)), () => `Cannot set object as part of the provided extension: it is not an extension of parent ${this.parent}`);
622
607
  this._extension = extension;
623
608
  }
624
609
  remove() {
@@ -712,7 +697,7 @@ class CoreFeatures {
712
697
  this.add(coreItself);
713
698
  const coreDef = (0, coreSpec_1.findCoreSpecVersion)(coreItself.url);
714
699
  if (!coreDef) {
715
- throw error(`Schema uses unknown version ${coreItself.url.version} of the ${coreItself.url.name} spec`);
700
+ throw error_2.ERRORS.UNKNOWN_LINK_VERSION.err(`Schema uses unknown version ${coreItself.url.version} of the ${coreItself.url.name} spec`);
716
701
  }
717
702
  this.coreDefinition = coreDef;
718
703
  }
@@ -739,7 +724,7 @@ class CoreFeatures {
739
724
  const url = this.coreDefinition.extractFeatureUrl(args);
740
725
  const existing = this.byIdentity.get(url.identity);
741
726
  if (existing) {
742
- throw error(`Duplicate inclusion of feature ${url.identity}`);
727
+ throw error_2.ERRORS.INVALID_LINK_DIRECTIVE_USAGE.err(`Duplicate inclusion of feature ${url.identity}`);
743
728
  }
744
729
  const imports = (0, coreSpec_1.extractCoreFeatureImports)(url, typedDirective);
745
730
  const feature = new CoreFeature(url, (_b = args.as) !== null && _b !== void 0 ? _b : url.name, directive, imports, args.for);
@@ -986,25 +971,15 @@ class Schema {
986
971
  addType(type) {
987
972
  const existing = this.type(type.name);
988
973
  if (existing) {
989
- if (existing.isBuiltIn) {
990
- }
991
- else {
992
- throw error(`Type ${type} already exists in this schema`);
993
- }
974
+ (0, utils_1.assert)(existing.isBuiltIn, () => `Type ${type} already exists in this schema`);
994
975
  }
995
976
  if (type.isAttached()) {
996
- if (type.parent == this) {
997
- return type;
998
- }
999
- throw error(`Cannot add type ${type} to this schema; it is already attached to another schema`);
977
+ (0, utils_1.assert)(type.parent == this, () => `Cannot add type ${type} to this schema; it is already attached to another schema`);
978
+ return type;
1000
979
  }
1001
980
  if (type.isBuiltIn) {
1002
- if (!this.isConstructed) {
1003
- this._builtInTypes.set(type.name, type);
1004
- }
1005
- else {
1006
- throw error(`Cannot add built-in ${type} to this schema (built-ins can only be added at schema construction time)`);
1007
- }
981
+ (0, utils_1.assert)(!this.isConstructed, `Cannot add built-in ${type} to this schema (built-ins can only be added at schema construction time)`);
982
+ this._builtInTypes.set(type.name, type);
1008
983
  }
1009
984
  else {
1010
985
  this._types.set(type.name, type);
@@ -1055,22 +1030,14 @@ class Schema {
1055
1030
  addDirectiveDefinition(directiveOrName) {
1056
1031
  const definition = typeof directiveOrName === 'string' ? new DirectiveDefinition(directiveOrName) : directiveOrName;
1057
1032
  const existing = this.directive(definition.name);
1058
- if (existing && !existing.isBuiltIn) {
1059
- throw error(`Directive ${definition} already exists in this schema`);
1060
- }
1033
+ (0, utils_1.assert)(!existing || existing.isBuiltIn, () => `Directive ${definition} already exists in this schema`);
1061
1034
  if (definition.isAttached()) {
1062
- if (definition.parent == this) {
1063
- return definition;
1064
- }
1065
- throw error(`Cannot add directive ${definition} to this schema; it is already attached to another schema`);
1035
+ (0, utils_1.assert)(definition.parent == this, () => `Cannot add directive ${definition} to this schema; it is already attached to another schema`);
1036
+ return definition;
1066
1037
  }
1067
1038
  if (definition.isBuiltIn) {
1068
- if (!this.isConstructed) {
1069
- this._builtInDirectives.set(definition.name, definition);
1070
- }
1071
- else {
1072
- throw error(`Cannot add built-in ${definition} to this schema (built-ins can only be added at schema construction time)`);
1073
- }
1039
+ (0, utils_1.assert)(!this.isConstructed, () => `Cannot add built-in ${definition} to this schema (built-ins can only be added at schema construction time)`);
1040
+ this._builtInDirectives.set(definition.name, definition);
1074
1041
  }
1075
1042
  else {
1076
1043
  this._directives.set(definition.name, definition);
@@ -1129,7 +1096,7 @@ class Schema {
1129
1096
  }
1130
1097
  elementByCoordinate(coordinate) {
1131
1098
  if (!coordinate.match(coordinateRegexp)) {
1132
- throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1099
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1133
1100
  }
1134
1101
  const argStartIdx = coordinate.indexOf('(');
1135
1102
  const start = argStartIdx < 0 ? coordinate : coordinate.slice(0, argStartIdx);
@@ -1140,7 +1107,7 @@ class Schema {
1140
1107
  const isDirective = typeOrDirectiveName.startsWith('@');
1141
1108
  if (isDirective) {
1142
1109
  if (fieldOrEnumName) {
1143
- throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1110
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1144
1111
  }
1145
1112
  const directive = this.directive(typeOrDirectiveName.slice(1));
1146
1113
  return argName ? directive === null || directive === void 0 ? void 0 : directive.argument(argName) : directive;
@@ -1157,16 +1124,16 @@ class Schema {
1157
1124
  return argName ? field === null || field === void 0 ? void 0 : field.argument(argName) : field;
1158
1125
  case 'InputObjectType':
1159
1126
  if (argName) {
1160
- throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1127
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1161
1128
  }
1162
1129
  return type.field(fieldOrEnumName);
1163
1130
  case 'EnumType':
1164
1131
  if (argName) {
1165
- throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1132
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1166
1133
  }
1167
1134
  return type.value(fieldOrEnumName);
1168
1135
  default:
1169
- throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1136
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
1170
1137
  }
1171
1138
  }
1172
1139
  }
@@ -1204,7 +1171,7 @@ class SchemaDefinition extends SchemaElement {
1204
1171
  const coreFeatures = schema.coreFeatures;
1205
1172
  if ((0, coreSpec_1.isCoreSpecDirectiveApplication)(applied)) {
1206
1173
  if (coreFeatures) {
1207
- throw error(`Invalid duplicate application of @core/@link`);
1174
+ throw error_2.ERRORS.INVALID_LINK_DIRECTIVE_USAGE.err(`Invalid duplicate application of @core/@link`);
1208
1175
  }
1209
1176
  const schemaDirective = applied;
1210
1177
  const args = schemaDirective.arguments();
@@ -1235,10 +1202,10 @@ class SchemaDefinition extends SchemaElement {
1235
1202
  this.checkUpdate();
1236
1203
  const obj = this.schema().type(nameOrType);
1237
1204
  if (!obj) {
1238
- throw new graphql_1.GraphQLError(`Cannot set schema ${rootKind} root to unknown type ${nameOrType}`);
1205
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Cannot set schema ${rootKind} root to unknown type ${nameOrType}`);
1239
1206
  }
1240
1207
  else if (obj.kind != 'ObjectType') {
1241
- throw new graphql_1.GraphQLError(`${defaultRootName(rootKind)} root type must be an Object type${rootKind === 'query' ? '' : ' if provided'}, it cannot be set to ${nameOrType} (an ${obj.kind}).`);
1208
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`${defaultRootName(rootKind)} root type must be an Object type${rootKind === 'query' ? '' : ' if provided'}, it cannot be set to ${nameOrType} (an ${obj.kind}).`);
1242
1209
  }
1243
1210
  toSet = new RootType(rootKind, obj);
1244
1211
  }
@@ -1267,9 +1234,7 @@ class SchemaDefinition extends SchemaElement {
1267
1234
  if (this._extensions.has(extension)) {
1268
1235
  return extension;
1269
1236
  }
1270
- if (extension.extendedElement) {
1271
- throw error(`Cannot add extension to this schema: extension is already added to another schema`);
1272
- }
1237
+ (0, utils_1.assert)(!extension.extendedElement, 'Cannot add extension to this schema: extension is already added to another schema');
1273
1238
  this._extensions.add(extension);
1274
1239
  Extension.prototype['setExtendedElement'].call(extension, this);
1275
1240
  this.onModification();
@@ -1372,10 +1337,10 @@ class FieldBasedType extends BaseNamedType {
1372
1337
  this.checkUpdate();
1373
1338
  const maybeItf = this.schema().type(nameOrItfOrItfImpl);
1374
1339
  if (!maybeItf) {
1375
- throw new graphql_1.GraphQLError(`Cannot implement unknown type ${nameOrItfOrItfImpl}`);
1340
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Cannot implement unknown type ${nameOrItfOrItfImpl}`);
1376
1341
  }
1377
1342
  else if (maybeItf.kind != 'InterfaceType') {
1378
- throw new graphql_1.GraphQLError(`Cannot implement non-interface type ${nameOrItfOrItfImpl} (of type ${maybeItf.kind})`);
1343
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Cannot implement non-interface type ${nameOrItfOrItfImpl} (of type ${maybeItf.kind})`);
1379
1344
  }
1380
1345
  itf = maybeItf;
1381
1346
  }
@@ -1428,10 +1393,10 @@ class FieldBasedType extends BaseNamedType {
1428
1393
  toAdd = nameOrField;
1429
1394
  }
1430
1395
  if (this.field(toAdd.name)) {
1431
- throw error(`Field ${toAdd.name} already exists on ${this}`);
1396
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Field ${toAdd.name} already exists on ${this}`);
1432
1397
  }
1433
1398
  if (type && !isOutputType(type)) {
1434
- throw error(`Invalid input type ${type} for field ${toAdd.name}: object and interface field types should be output types.`);
1399
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid input type ${type} for field ${toAdd.name}: object and interface field types should be output types.`);
1435
1400
  }
1436
1401
  this._fields.set(toAdd.name, toAdd);
1437
1402
  this._cachedNonBuiltInFields = undefined;
@@ -1577,10 +1542,10 @@ class UnionType extends BaseNamedType {
1577
1542
  this.checkUpdate();
1578
1543
  const maybeObj = this.schema().type(nameOrTypeOrMember);
1579
1544
  if (!maybeObj) {
1580
- throw new graphql_1.GraphQLError(`Cannot add unknown type ${nameOrTypeOrMember} as member of union type ${this.name}`);
1545
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Cannot add unknown type ${nameOrTypeOrMember} as member of union type ${this.name}`);
1581
1546
  }
1582
1547
  else if (maybeObj.kind != 'ObjectType') {
1583
- throw new graphql_1.GraphQLError(`Cannot add non-object type ${nameOrTypeOrMember} (of type ${maybeObj.kind}) as member of union type ${this.name}`);
1548
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Cannot add non-object type ${nameOrTypeOrMember} (of type ${maybeObj.kind}) as member of union type ${this.name}`);
1584
1549
  }
1585
1550
  obj = maybeObj;
1586
1551
  }
@@ -1720,10 +1685,10 @@ class InputObjectType extends BaseNamedType {
1720
1685
  const toAdd = typeof nameOrField === 'string' ? new InputFieldDefinition(nameOrField) : nameOrField;
1721
1686
  this.checkUpdate(toAdd);
1722
1687
  if (this.field(toAdd.name)) {
1723
- throw error(`Field ${toAdd.name} already exists on ${this}`);
1688
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Field ${toAdd.name} already exists on ${this}`);
1724
1689
  }
1725
1690
  if (type && !isInputType(type)) {
1726
- throw error(`Invalid output type ${type} for field ${toAdd.name}: input field types should be input types.`);
1691
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid output type ${type} for field ${toAdd.name}: input field types should be input types.`);
1727
1692
  }
1728
1693
  this._fields.set(toAdd.name, toAdd);
1729
1694
  this._cachedFieldsArray = undefined;
@@ -1843,15 +1808,15 @@ class FieldDefinition extends NamedSchemaElementWithType {
1843
1808
  const existing = this.argument(toAdd.name);
1844
1809
  if (existing) {
1845
1810
  if (type && existing.type && !(0, types_1.sameType)(type, existing.type)) {
1846
- throw error(`Argument ${toAdd.name} already exists on field ${this.name} with a different type (${existing.type})`);
1811
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Argument ${toAdd.name} already exists on field ${this.name} with a different type (${existing.type})`);
1847
1812
  }
1848
1813
  if (defaultValue && (!existing.defaultValue || !(0, values_1.valueEquals)(defaultValue, existing.defaultValue))) {
1849
- throw error(`Argument ${toAdd.name} already exists on field ${this.name} with a different default value (${(0, values_1.valueToString)(existing.defaultValue)})`);
1814
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Argument ${toAdd.name} already exists on field ${this.name} with a different default value (${(0, values_1.valueToString)(existing.defaultValue)})`);
1850
1815
  }
1851
1816
  return existing;
1852
1817
  }
1853
1818
  if (type && !isInputType(type)) {
1854
- throw error(`Invalid output type ${type} for argument ${toAdd.name} of ${this}: arguments should be input types.`);
1819
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid output type ${type} for argument ${toAdd.name} of ${this}: arguments should be input types.`);
1855
1820
  }
1856
1821
  this._args.set(toAdd.name, toAdd);
1857
1822
  Element.prototype['setParent'].call(toAdd, this);
@@ -1870,9 +1835,7 @@ class FieldDefinition extends NamedSchemaElementWithType {
1870
1835
  setOfExtension(extension) {
1871
1836
  var _a;
1872
1837
  this.checkUpdate();
1873
- if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
1874
- throw error(`Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
1875
- }
1838
+ (0, utils_1.assert)(!extension || ((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension)), () => `Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
1876
1839
  this._extension = extension;
1877
1840
  this.onModification();
1878
1841
  }
@@ -1944,9 +1907,7 @@ class InputFieldDefinition extends NamedSchemaElementWithType {
1944
1907
  setOfExtension(extension) {
1945
1908
  var _a;
1946
1909
  this.checkUpdate();
1947
- if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
1948
- throw error(`Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
1949
- }
1910
+ (0, utils_1.assert)(!extension || ((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension)), () => `Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
1950
1911
  this._extension = extension;
1951
1912
  this.onModification();
1952
1913
  }
@@ -2039,9 +2000,7 @@ class EnumValue extends NamedSchemaElement {
2039
2000
  setOfExtension(extension) {
2040
2001
  var _a;
2041
2002
  this.checkUpdate();
2042
- if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
2043
- throw error(`Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
2044
- }
2003
+ (0, utils_1.assert)(!extension || ((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension)), () => `Cannot mark field ${this.name} as part of the provided extension: it is not an extension of enum value parent type ${this.parent}`);
2045
2004
  this._extension = extension;
2046
2005
  this.onModification();
2047
2006
  }
@@ -2100,7 +2059,7 @@ class DirectiveDefinition extends NamedSchemaElement {
2100
2059
  toAdd = nameOrArg;
2101
2060
  }
2102
2061
  if (this.argument(toAdd.name)) {
2103
- throw error(`Argument ${toAdd.name} already exists on field ${this.name}`);
2062
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Argument ${toAdd.name} already exists on field ${this.name}`);
2104
2063
  }
2105
2064
  this._args.set(toAdd.name, toAdd);
2106
2065
  Element.prototype['setParent'].call(toAdd, this);
@@ -2208,9 +2167,7 @@ class Directive extends Element {
2208
2167
  return this._args;
2209
2168
  }
2210
2169
  const definition = this.definition;
2211
- if (!definition) {
2212
- throw error(`Cannot include default values for arguments: cannot find directive definition for ${this.name}`);
2213
- }
2170
+ (0, utils_1.assert)(definition, () => `Cannot include default values for arguments: cannot find directive definition for ${this.name}`);
2214
2171
  const updated = Object.create(null);
2215
2172
  for (const argDef of definition.arguments()) {
2216
2173
  updated[argDef.name] = (0, values_1.withDefaultValues)(this._args[argDef.name], argDef);
@@ -2259,14 +2216,8 @@ class Directive extends Element {
2259
2216
  this.checkUpdate();
2260
2217
  if (extension) {
2261
2218
  const parent = this.parent;
2262
- if (parent instanceof SchemaDefinition || parent instanceof BaseNamedType) {
2263
- if (!parent.extensions().has(extension)) {
2264
- throw error(`Cannot mark directive ${this.name} as part of the provided extension: it is not an extension of parent ${parent}`);
2265
- }
2266
- }
2267
- else {
2268
- throw error(`Can only mark directive parts of extensions when directly apply to type or schema definition.`);
2269
- }
2219
+ (0, utils_1.assert)(parent instanceof SchemaDefinition || parent instanceof BaseNamedType, 'Can only mark directive parts of extensions when directly apply to type or schema definition.');
2220
+ (0, utils_1.assert)(parent.extensions().has(extension), () => `Cannot mark directive ${this.name} as part of the provided extension: it is not an extension of parent ${parent}`);
2270
2221
  }
2271
2222
  this._extension = extension;
2272
2223
  this.onModification();
@@ -2491,7 +2442,7 @@ function variableDefinitionsFromAST(schema, definitionNodes) {
2491
2442
  for (const definitionNode of definitionNodes) {
2492
2443
  if (!definitions.add(variableDefinitionFromAST(schema, definitionNode))) {
2493
2444
  const name = definitionNode.variable.name.value;
2494
- throw new graphql_1.GraphQLError(`Duplicate definition for variable ${name}`, definitionNodes.filter(n => n.variable.name.value === name));
2445
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Duplicate definition for variable ${name}`, { nodes: definitionNodes.filter(n => n.variable.name.value === name) });
2495
2446
  }
2496
2447
  }
2497
2448
  return definitions;
@@ -2501,7 +2452,7 @@ function variableDefinitionFromAST(schema, definitionNode) {
2501
2452
  const variable = new Variable(definitionNode.variable.name.value);
2502
2453
  const type = typeFromAST(schema, definitionNode.type);
2503
2454
  if (!isInputType(type)) {
2504
- throw new graphql_1.GraphQLError(`Invalid type "${type}" for variable $${variable}: not an input type`, definitionNode.type);
2455
+ throw error_2.ERRORS.INVALID_GRAPHQL.err(`Invalid type "${type}" for variable $${variable}: not an input type`, { nodes: definitionNode.type });
2505
2456
  }
2506
2457
  const def = new VariableDefinition(schema, variable, type, definitionNode.defaultValue ? (0, values_1.valueFromAST)(definitionNode.defaultValue, type) : undefined);
2507
2458
  return def;