graphql 16.14.1 → 16.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/error/GraphQLError.d.ts +5 -1
  2. package/error/GraphQLError.js +12 -7
  3. package/error/GraphQLError.mjs +13 -6
  4. package/error/locatedError.d.ts +6 -4
  5. package/error/locatedError.js +6 -4
  6. package/error/locatedError.mjs +6 -4
  7. package/execution/collectFields.d.ts +1 -0
  8. package/execution/collectFields.js +9 -0
  9. package/execution/collectFields.mjs +9 -0
  10. package/execution/execute.d.ts +9 -10
  11. package/execution/execute.js +44 -29
  12. package/execution/execute.mjs +44 -29
  13. package/execution/mapAsyncIterator.js +12 -11
  14. package/execution/mapAsyncIterator.mjs +12 -11
  15. package/execution/subscribe.d.ts +5 -2
  16. package/execution/subscribe.js +5 -2
  17. package/execution/subscribe.mjs +5 -2
  18. package/execution/values.d.ts +43 -21
  19. package/execution/values.js +52 -24
  20. package/execution/values.mjs +51 -23
  21. package/graphql.d.ts +8 -14
  22. package/graphql.js +16 -15
  23. package/graphql.mjs +11 -15
  24. package/jsutils/SetMap.d.ts +14 -0
  25. package/jsutils/SetMap.js +48 -0
  26. package/jsutils/SetMap.mjs +39 -0
  27. package/jsutils/isIterableObject.d.ts +2 -0
  28. package/jsutils/isIterableObject.js +2 -0
  29. package/jsutils/isIterableObject.mjs +2 -0
  30. package/jsutils/keyMap.d.ts +2 -0
  31. package/jsutils/keyMap.js +2 -0
  32. package/jsutils/keyMap.mjs +2 -0
  33. package/jsutils/keyValMap.d.ts +3 -3
  34. package/jsutils/keyValMap.js +3 -3
  35. package/jsutils/keyValMap.mjs +3 -3
  36. package/language/ast.d.ts +2 -6
  37. package/language/ast.js +2 -6
  38. package/language/ast.mjs +2 -6
  39. package/language/lexer.d.ts +6 -0
  40. package/language/lexer.js +22 -0
  41. package/language/lexer.mjs +22 -0
  42. package/language/location.d.ts +8 -3
  43. package/language/location.js +57 -17
  44. package/language/location.mjs +56 -16
  45. package/language/parser.d.ts +27 -13
  46. package/language/parser.js +31 -9
  47. package/language/parser.mjs +31 -9
  48. package/language/predicates.d.ts +10 -3
  49. package/language/predicates.js +10 -3
  50. package/language/predicates.mjs +10 -3
  51. package/language/printLocation.d.ts +2 -6
  52. package/language/printLocation.js +2 -6
  53. package/language/printLocation.mjs +2 -6
  54. package/language/printer.d.ts +22 -3
  55. package/language/printer.js +394 -308
  56. package/language/printer.mjs +394 -308
  57. package/language/reducer.d.ts +32 -0
  58. package/language/reducer.js +95 -0
  59. package/language/reducer.mjs +86 -0
  60. package/language/source.d.ts +4 -5
  61. package/language/source.js +4 -5
  62. package/language/source.mjs +4 -5
  63. package/language/visitor.d.ts +16 -10
  64. package/language/visitor.js +15 -7
  65. package/language/visitor.mjs +15 -7
  66. package/package.json +1 -4
  67. package/type/definition.d.ts +190 -122
  68. package/type/definition.js +175 -102
  69. package/type/definition.mjs +174 -101
  70. package/type/directives.d.ts +14 -8
  71. package/type/directives.js +13 -7
  72. package/type/directives.mjs +13 -7
  73. package/type/scalars.js +8 -11
  74. package/type/scalars.mjs +1 -1
  75. package/type/schema.d.ts +38 -13
  76. package/type/schema.js +36 -11
  77. package/type/schema.mjs +36 -11
  78. package/type/validate.d.ts +1 -3
  79. package/type/validate.js +1 -3
  80. package/type/validate.mjs +1 -3
  81. package/utilities/TypeInfo.d.ts +15 -11
  82. package/utilities/TypeInfo.js +15 -11
  83. package/utilities/TypeInfo.mjs +15 -11
  84. package/utilities/assertValidName.d.ts +1 -1
  85. package/utilities/assertValidName.js +1 -1
  86. package/utilities/assertValidName.mjs +1 -1
  87. package/utilities/astFromValue.d.ts +3 -1
  88. package/utilities/astFromValue.js +3 -1
  89. package/utilities/astFromValue.mjs +3 -1
  90. package/utilities/buildASTSchema.d.ts +8 -8
  91. package/utilities/buildASTSchema.js +9 -20
  92. package/utilities/buildASTSchema.mjs +9 -20
  93. package/utilities/buildClientSchema.d.ts +6 -2
  94. package/utilities/buildClientSchema.js +6 -2
  95. package/utilities/buildClientSchema.mjs +6 -2
  96. package/utilities/coerceInputValue.d.ts +9 -3
  97. package/utilities/coerceInputValue.js +60 -13
  98. package/utilities/coerceInputValue.mjs +58 -13
  99. package/utilities/concatAST.d.ts +4 -1
  100. package/utilities/concatAST.js +4 -1
  101. package/utilities/concatAST.mjs +4 -1
  102. package/utilities/extendSchema.d.ts +7 -4
  103. package/utilities/extendSchema.js +7 -4
  104. package/utilities/extendSchema.mjs +7 -4
  105. package/utilities/findBreakingChanges.d.ts +2 -2
  106. package/utilities/findBreakingChanges.js +2 -2
  107. package/utilities/findBreakingChanges.mjs +2 -2
  108. package/utilities/getIntrospectionQuery.d.ts +9 -9
  109. package/utilities/getIntrospectionQuery.js +8 -8
  110. package/utilities/getIntrospectionQuery.mjs +8 -8
  111. package/utilities/getOperationAST.d.ts +2 -2
  112. package/utilities/getOperationAST.js +2 -2
  113. package/utilities/getOperationAST.mjs +2 -2
  114. package/utilities/getOperationRootType.d.ts +3 -1
  115. package/utilities/getOperationRootType.js +3 -1
  116. package/utilities/getOperationRootType.mjs +3 -1
  117. package/utilities/introspectionFromSchema.d.ts +12 -4
  118. package/utilities/introspectionFromSchema.js +12 -4
  119. package/utilities/introspectionFromSchema.mjs +12 -4
  120. package/utilities/lexicographicSortSchema.d.ts +17 -13
  121. package/utilities/lexicographicSortSchema.js +17 -13
  122. package/utilities/lexicographicSortSchema.mjs +17 -13
  123. package/utilities/printSchema.d.ts +7 -4
  124. package/utilities/printSchema.js +7 -4
  125. package/utilities/printSchema.mjs +7 -4
  126. package/utilities/resolveSchemaCoordinate.d.ts +9 -8
  127. package/utilities/resolveSchemaCoordinate.js +9 -8
  128. package/utilities/resolveSchemaCoordinate.mjs +9 -8
  129. package/utilities/separateOperations.d.ts +2 -2
  130. package/utilities/separateOperations.js +2 -2
  131. package/utilities/separateOperations.mjs +2 -2
  132. package/utilities/stripIgnoredCharacters.d.ts +19 -5
  133. package/utilities/stripIgnoredCharacters.js +19 -5
  134. package/utilities/stripIgnoredCharacters.mjs +19 -5
  135. package/utilities/typeComparators.d.ts +1 -5
  136. package/utilities/typeComparators.js +1 -5
  137. package/utilities/typeComparators.mjs +1 -5
  138. package/utilities/valueFromAST.js +4 -4
  139. package/utilities/valueFromAST.mjs +4 -4
  140. package/utilities/valueFromASTUntyped.d.ts +1 -3
  141. package/utilities/valueFromASTUntyped.js +1 -3
  142. package/utilities/valueFromASTUntyped.mjs +1 -3
  143. package/validation/ValidationContext.d.ts +22 -3
  144. package/validation/ValidationContext.js +84 -27
  145. package/validation/ValidationContext.mjs +82 -27
  146. package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -4
  147. package/validation/rules/ExecutableDefinitionsRule.js +6 -4
  148. package/validation/rules/ExecutableDefinitionsRule.mjs +6 -4
  149. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +4 -4
  150. package/validation/rules/FieldsOnCorrectTypeRule.js +10 -6
  151. package/validation/rules/FieldsOnCorrectTypeRule.mjs +12 -6
  152. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -4
  153. package/validation/rules/FragmentsOnCompositeTypesRule.js +6 -4
  154. package/validation/rules/FragmentsOnCompositeTypesRule.mjs +6 -4
  155. package/validation/rules/KnownArgumentNamesRule.d.ts +4 -4
  156. package/validation/rules/KnownArgumentNamesRule.js +26 -17
  157. package/validation/rules/KnownArgumentNamesRule.mjs +21 -11
  158. package/validation/rules/KnownDirectivesRule.d.ts +1 -3
  159. package/validation/rules/KnownDirectivesRule.js +1 -3
  160. package/validation/rules/KnownDirectivesRule.mjs +1 -3
  161. package/validation/rules/KnownFragmentNamesRule.d.ts +4 -4
  162. package/validation/rules/KnownFragmentNamesRule.js +4 -4
  163. package/validation/rules/KnownFragmentNamesRule.mjs +4 -4
  164. package/validation/rules/KnownTypeNamesRule.d.ts +1 -3
  165. package/validation/rules/KnownTypeNamesRule.js +7 -7
  166. package/validation/rules/KnownTypeNamesRule.mjs +7 -7
  167. package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -4
  168. package/validation/rules/LoneAnonymousOperationRule.js +6 -4
  169. package/validation/rules/LoneAnonymousOperationRule.mjs +6 -4
  170. package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -4
  171. package/validation/rules/MaxIntrospectionDepthRule.js +44 -19
  172. package/validation/rules/MaxIntrospectionDepthRule.mjs +44 -19
  173. package/validation/rules/NoFragmentCyclesRule.d.ts +1 -3
  174. package/validation/rules/NoFragmentCyclesRule.js +1 -3
  175. package/validation/rules/NoFragmentCyclesRule.mjs +1 -3
  176. package/validation/rules/NoUndefinedVariablesRule.d.ts +4 -4
  177. package/validation/rules/NoUndefinedVariablesRule.js +4 -4
  178. package/validation/rules/NoUndefinedVariablesRule.mjs +4 -4
  179. package/validation/rules/NoUnusedFragmentsRule.d.ts +4 -4
  180. package/validation/rules/NoUnusedFragmentsRule.js +10 -14
  181. package/validation/rules/NoUnusedFragmentsRule.mjs +10 -14
  182. package/validation/rules/NoUnusedVariablesRule.d.ts +4 -4
  183. package/validation/rules/NoUnusedVariablesRule.js +4 -4
  184. package/validation/rules/NoUnusedVariablesRule.mjs +4 -4
  185. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +8 -6
  186. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +552 -354
  187. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +545 -352
  188. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -4
  189. package/validation/rules/PossibleFragmentSpreadsRule.js +6 -4
  190. package/validation/rules/PossibleFragmentSpreadsRule.mjs +6 -4
  191. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -4
  192. package/validation/rules/ProvidedRequiredArgumentsRule.js +6 -4
  193. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +6 -4
  194. package/validation/rules/ScalarLeafsRule.d.ts +1 -3
  195. package/validation/rules/ScalarLeafsRule.js +1 -3
  196. package/validation/rules/ScalarLeafsRule.mjs +1 -3
  197. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -4
  198. package/validation/rules/SingleFieldSubscriptionsRule.js +50 -9
  199. package/validation/rules/SingleFieldSubscriptionsRule.mjs +50 -9
  200. package/validation/rules/UniqueArgumentNamesRule.d.ts +4 -4
  201. package/validation/rules/UniqueArgumentNamesRule.js +4 -4
  202. package/validation/rules/UniqueArgumentNamesRule.mjs +4 -4
  203. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -4
  204. package/validation/rules/UniqueDirectivesPerLocationRule.js +6 -4
  205. package/validation/rules/UniqueDirectivesPerLocationRule.mjs +6 -4
  206. package/validation/rules/UniqueFragmentNamesRule.d.ts +4 -4
  207. package/validation/rules/UniqueFragmentNamesRule.js +4 -4
  208. package/validation/rules/UniqueFragmentNamesRule.mjs +4 -4
  209. package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -4
  210. package/validation/rules/UniqueInputFieldNamesRule.js +6 -4
  211. package/validation/rules/UniqueInputFieldNamesRule.mjs +6 -4
  212. package/validation/rules/UniqueOperationNamesRule.d.ts +4 -4
  213. package/validation/rules/UniqueOperationNamesRule.js +4 -4
  214. package/validation/rules/UniqueOperationNamesRule.mjs +4 -4
  215. package/validation/rules/UniqueVariableNamesRule.d.ts +4 -4
  216. package/validation/rules/UniqueVariableNamesRule.js +4 -4
  217. package/validation/rules/UniqueVariableNamesRule.mjs +4 -4
  218. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +4 -4
  219. package/validation/rules/ValuesOfCorrectTypeRule.js +29 -23
  220. package/validation/rules/ValuesOfCorrectTypeRule.mjs +24 -14
  221. package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -4
  222. package/validation/rules/VariablesAreInputTypesRule.js +6 -4
  223. package/validation/rules/VariablesAreInputTypesRule.mjs +6 -4
  224. package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -4
  225. package/validation/rules/VariablesInAllowedPositionRule.js +6 -4
  226. package/validation/rules/VariablesInAllowedPositionRule.mjs +6 -4
  227. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +4 -4
  228. package/validation/rules/custom/NoDeprecatedCustomRule.js +4 -4
  229. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +4 -4
  230. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +7 -5
  231. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +7 -5
  232. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +7 -5
  233. package/validation/validate.d.ts +2 -0
  234. package/validation/validate.js +14 -2
  235. package/validation/validate.mjs +13 -2
  236. package/validation/validationAbortedError.d.ts +3 -0
  237. package/validation/validationAbortedError.js +14 -0
  238. package/validation/validationAbortedError.mjs +4 -0
  239. package/version.js +3 -3
  240. package/version.mjs +3 -3
@@ -1052,13 +1052,15 @@ function assertAbstractType(type) {
1052
1052
  * @typeParam T - The GraphQL type wrapped by this list type.
1053
1053
  * @example
1054
1054
  * ```ts
1055
- * const PersonType = new GraphQLObjectType({
1055
+ * import { GraphQLList, GraphQLObjectType } from 'graphql';
1056
+ *
1057
+ * const PersonType: GraphQLObjectType = new GraphQLObjectType({
1056
1058
  * name: 'Person',
1057
1059
  * fields: () => ({
1058
1060
  * parents: { type: new GraphQLList(PersonType) },
1059
1061
  * children: { type: new GraphQLList(PersonType) },
1060
- * })
1061
- * })
1062
+ * }),
1063
+ * });
1062
1064
  * ```
1063
1065
  */
1064
1066
 
@@ -1141,12 +1143,14 @@ class GraphQLList {
1141
1143
  * @typeParam T - The nullable GraphQL type wrapped by this non-null type.
1142
1144
  * @example
1143
1145
  * ```ts
1146
+ * import { GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql';
1147
+ *
1144
1148
  * const RowType = new GraphQLObjectType({
1145
1149
  * name: 'Row',
1146
1150
  * fields: () => ({
1147
1151
  * id: { type: new GraphQLNonNull(GraphQLString) },
1148
- * })
1149
- * })
1152
+ * }),
1153
+ * });
1150
1154
  * ```
1151
1155
  *
1152
1156
  * Note: the enforcement of non-nullability occurs within the executor.
@@ -1196,9 +1200,7 @@ class GraphQLNonNull {
1196
1200
  * import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
1197
1201
  *
1198
1202
  * const requiredString = new GraphQLNonNull(GraphQLString);
1199
- * const requiredStringList = new GraphQLNonNull(
1200
- * new GraphQLList(GraphQLString),
1201
- * );
1203
+ * const requiredStringList = new GraphQLNonNull(new GraphQLList(GraphQLString));
1202
1204
  *
1203
1205
  * requiredString.toString(); // => 'String!'
1204
1206
  * requiredStringList.toString(); // => '[String]!'
@@ -1305,9 +1307,7 @@ function isNullableType(type) {
1305
1307
  * assertNullableType,
1306
1308
  * } from 'graphql/type';
1307
1309
  *
1308
- * const nullableType = assertNullableType(GraphQLString);
1309
- *
1310
- * nullableType; // => GraphQLString
1310
+ * const nullableType = assertNullableType(GraphQLString); // => GraphQLString
1311
1311
  * assertNullableType(new GraphQLNonNull(GraphQLString)); // throws an error
1312
1312
  * ```
1313
1313
  */
@@ -1429,11 +1429,8 @@ function getNamedType(type) {
1429
1429
  * ```ts
1430
1430
  * import { GraphQLString, resolveReadonlyArrayThunk } from 'graphql/type';
1431
1431
  *
1432
- * const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]);
1433
- * const fields = resolveReadonlyArrayThunk([GraphQLString]);
1434
- *
1435
- * lazyFields; // => [GraphQLString]
1436
- * fields; // => [GraphQLString]
1432
+ * const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]); // => [GraphQLString]
1433
+ * const fields = resolveReadonlyArrayThunk([GraphQLString]); // => [GraphQLString]
1437
1434
  * ```
1438
1435
  */
1439
1436
  function resolveReadonlyArrayThunk(thunk) {
@@ -1484,21 +1481,29 @@ function resolveObjMapThunk(thunk) {
1484
1481
  * @typeParam TExternal - The serialized representation exposed in GraphQL results.
1485
1482
  * @example
1486
1483
  * ```ts
1484
+ * import { GraphQLScalarType } from 'graphql/type';
1485
+ *
1487
1486
  * const OddType = new GraphQLScalarType({
1488
1487
  * name: 'Odd',
1489
1488
  * serialize: (value) => {
1490
- * if (!Number.isFinite(value)) {
1489
+ * if (typeof value !== 'number' || !Number.isInteger(value)) {
1491
1490
  * throw new Error(
1492
- * `Scalar "Odd" cannot represent "${value}" since it is not a finite number.`,
1491
+ * `Scalar "Odd" cannot represent "${value}" since it is not an integer.`,
1493
1492
  * );
1494
1493
  * }
1495
1494
  *
1496
1495
  * if (value % 2 === 0) {
1497
- * throw new Error(`Scalar "Odd" cannot represent "${value}" since it is even.`);
1496
+ * throw new Error(
1497
+ * `Scalar "Odd" cannot represent "${value}" since it is even.`,
1498
+ * );
1498
1499
  * }
1499
1500
  * return value;
1500
- * }
1501
+ * },
1501
1502
  * });
1503
+ *
1504
+ * OddType.serialize(3); // => 3
1505
+ * OddType.serialize(2); // throws an error
1506
+ * OddType.serialize(1.5); // throws an error
1502
1507
  * ```
1503
1508
  */
1504
1509
  class GraphQLScalarType {
@@ -1514,7 +1519,7 @@ class GraphQLScalarType {
1514
1519
 
1515
1520
  /** Function that converts AST input literals into this scalar's internal value. */
1516
1521
 
1517
- /** Extension fields to include in the formatted result. */
1522
+ /** Custom extension fields reserved for users. */
1518
1523
 
1519
1524
  /** AST node from which this schema element was built, if available. */
1520
1525
 
@@ -1525,6 +1530,7 @@ class GraphQLScalarType {
1525
1530
  * @param config - Configuration describing this object.
1526
1531
  * @example
1527
1532
  * ```ts
1533
+ * import assert from 'node:assert/strict';
1528
1534
  * import { Kind, parse } from 'graphql/language';
1529
1535
  * import { GraphQLScalarType } from 'graphql/type';
1530
1536
  *
@@ -1534,42 +1540,43 @@ class GraphQLScalarType {
1534
1540
  *
1535
1541
  * extend scalar Odd @specifiedBy(url: "https://example.com/odd-v2")
1536
1542
  * `);
1543
+ * assert(document.definitions[0].kind === Kind.SCALAR_TYPE_DEFINITION);
1544
+ * assert(document.definitions[1].kind === Kind.SCALAR_TYPE_EXTENSION);
1545
+ *
1546
+ * const ensureOdd = (value: unknown) => {
1547
+ * if (
1548
+ * typeof value !== 'number' ||
1549
+ * !Number.isInteger(value) ||
1550
+ * value % 2 === 0
1551
+ * ) {
1552
+ * throw new TypeError('Odd can only accept odd integers.');
1553
+ * }
1554
+ * return value;
1555
+ * };
1537
1556
  *
1538
1557
  * const Odd = new GraphQLScalarType({
1539
1558
  * name: 'Odd',
1540
1559
  * description: 'Odd integer values.',
1541
1560
  * specifiedByURL: 'https://example.com/odd',
1542
- * serialize: (value) => {
1543
- * if (typeof value !== 'number' || value % 2 === 0) {
1544
- * throw new TypeError('Odd can only serialize odd numbers.');
1545
- * }
1546
- * return value;
1547
- * },
1548
- * parseValue: (value) => {
1549
- * if (typeof value !== 'number' || value % 2 === 0) {
1550
- * throw new TypeError('Odd can only parse odd numbers.');
1551
- * }
1552
- * return value;
1553
- * },
1561
+ * serialize: ensureOdd,
1562
+ * parseValue: ensureOdd,
1554
1563
  * parseLiteral: (ast) => {
1555
1564
  * if (ast.kind !== Kind.INT) {
1556
1565
  * throw new TypeError('Odd can only parse integer literals.');
1557
1566
  * }
1558
- * const value = Number(ast.value);
1559
- * if (value % 2 === 0) {
1560
- * throw new TypeError('Odd can only parse odd integer literals.');
1561
- * }
1562
- * return value;
1567
+ * return ensureOdd(Number(ast.value));
1563
1568
  * },
1564
1569
  * extensions: { numeric: true },
1565
1570
  * astNode: document.definitions[0],
1566
- * extensionASTNodes: [ document.definitions[1] ],
1571
+ * extensionASTNodes: [document.definitions[1]],
1567
1572
  * });
1568
1573
  *
1569
1574
  * Odd.description; // => 'Odd integer values.'
1570
1575
  * Odd.specifiedByURL; // => 'https://example.com/odd'
1571
1576
  * Odd.serialize(3); // => 3
1572
1577
  * Odd.parseValue(5); // => 5
1578
+ * Odd.parseValue(2); // throws an error
1579
+ * Odd.parseValue(1.5); // throws an error
1573
1580
  * Odd.extensions; // => { numeric: true }
1574
1581
  * ```
1575
1582
  */
@@ -1725,6 +1732,8 @@ exports.GraphQLScalarType = GraphQLScalarType;
1725
1732
  * @typeParam TContext - Context object type passed to resolvers.
1726
1733
  * @example
1727
1734
  * ```ts
1735
+ * import { GraphQLInt, GraphQLObjectType, GraphQLString } from 'graphql';
1736
+ *
1728
1737
  * const AddressType = new GraphQLObjectType({
1729
1738
  * name: 'Address',
1730
1739
  * fields: {
@@ -1733,10 +1742,10 @@ exports.GraphQLScalarType = GraphQLScalarType;
1733
1742
  * formatted: {
1734
1743
  * type: GraphQLString,
1735
1744
  * resolve: (obj) => {
1736
- * return obj.number + ' ' + obj.street
1737
- * }
1738
- * }
1739
- * }
1745
+ * return obj.number + ' ' + obj.street;
1746
+ * },
1747
+ * },
1748
+ * },
1740
1749
  * });
1741
1750
  * ```
1742
1751
  * @example
@@ -1745,12 +1754,14 @@ exports.GraphQLScalarType = GraphQLScalarType;
1745
1754
  * thunk) to supply the fields lazily.
1746
1755
  *
1747
1756
  * ```ts
1748
- * const PersonType = new GraphQLObjectType({
1757
+ * import { GraphQLObjectType, GraphQLString } from 'graphql';
1758
+ *
1759
+ * const PersonType: GraphQLObjectType = new GraphQLObjectType({
1749
1760
  * name: 'Person',
1750
1761
  * fields: () => ({
1751
1762
  * name: { type: GraphQLString },
1752
1763
  * bestFriend: { type: PersonType },
1753
- * })
1764
+ * }),
1754
1765
  * });
1755
1766
  * ```
1756
1767
  */
@@ -1761,7 +1772,7 @@ class GraphQLObjectType {
1761
1772
 
1762
1773
  /** Predicate used to determine whether a runtime value belongs to this object type. */
1763
1774
 
1764
- /** Extension fields to include in the formatted result. */
1775
+ /** Custom extension fields reserved for users. */
1765
1776
 
1766
1777
  /** AST node from which this schema element was built, if available. */
1767
1778
 
@@ -1772,8 +1783,9 @@ class GraphQLObjectType {
1772
1783
  * @param config - Configuration describing this object.
1773
1784
  * @example
1774
1785
  * ```ts
1786
+ * import assert from 'node:assert/strict';
1775
1787
  * // Configure an object type with interfaces, fields, arguments, and metadata.
1776
- * import { parse } from 'graphql/language';
1788
+ * import { parse, Kind } from 'graphql/language';
1777
1789
  * import {
1778
1790
  * GraphQLID,
1779
1791
  * GraphQLInterfaceType,
@@ -1792,9 +1804,11 @@ class GraphQLObjectType {
1792
1804
  * displayName: String
1793
1805
  * }
1794
1806
  * `);
1807
+ * assert(document.definitions[0].kind === Kind.OBJECT_TYPE_DEFINITION);
1808
+ * assert(document.definitions[1].kind === Kind.OBJECT_TYPE_EXTENSION);
1795
1809
  * const definition = document.definitions[0];
1796
- * const nameField = definition.fields[1];
1797
- * const formatArg = nameField.arguments[0];
1810
+ * const nameField = definition.fields?.[1];
1811
+ * const formatArg = nameField?.arguments?.[0];
1798
1812
  *
1799
1813
  * const Node = new GraphQLInterfaceType({
1800
1814
  * name: 'Node',
@@ -1835,7 +1849,7 @@ class GraphQLObjectType {
1835
1849
  * },
1836
1850
  * extensions: { entity: 'User' },
1837
1851
  * astNode: definition,
1838
- * extensionASTNodes: [ document.definitions[1] ],
1852
+ * extensionASTNodes: [document.definitions[1]],
1839
1853
  * });
1840
1854
  *
1841
1855
  * User.name; // => 'User'
@@ -2178,17 +2192,26 @@ function argsToArgsConfig(args) {
2178
2192
  * import {
2179
2193
  * GraphQLInt,
2180
2194
  * GraphQLNonNull,
2195
+ * GraphQLObjectType,
2181
2196
  * GraphQLString,
2182
2197
  * isRequiredArgument,
2183
2198
  * } from 'graphql/type';
2184
2199
  *
2185
- * const requiredArgument = { name: 'id', type: new GraphQLNonNull(GraphQLInt) };
2186
- * const optionalArgument = { name: 'name', type: GraphQLString };
2187
- * const argumentWithDefault = {
2188
- * name: 'limit',
2189
- * type: new GraphQLNonNull(GraphQLInt),
2190
- * defaultValue: 10,
2191
- * };
2200
+ * const Query = new GraphQLObjectType({
2201
+ * name: 'Query',
2202
+ * fields: {
2203
+ * greeting: {
2204
+ * type: GraphQLString,
2205
+ * args: {
2206
+ * id: { type: new GraphQLNonNull(GraphQLInt) },
2207
+ * name: { type: GraphQLString },
2208
+ * limit: { type: new GraphQLNonNull(GraphQLInt), defaultValue: 10 },
2209
+ * },
2210
+ * },
2211
+ * },
2212
+ * });
2213
+ * const [requiredArgument, optionalArgument, argumentWithDefault] =
2214
+ * Query.getFields().greeting.args;
2192
2215
  *
2193
2216
  * isRequiredArgument(requiredArgument); // => true
2194
2217
  * isRequiredArgument(optionalArgument); // => false
@@ -2213,11 +2236,13 @@ function isRequiredArgument(arg) {
2213
2236
  * when the field is resolved.
2214
2237
  * @example
2215
2238
  * ```ts
2239
+ * import { GraphQLInterfaceType, GraphQLString } from 'graphql';
2240
+ *
2216
2241
  * const EntityType = new GraphQLInterfaceType({
2217
2242
  * name: 'Entity',
2218
2243
  * fields: {
2219
- * name: { type: GraphQLString }
2220
- * }
2244
+ * name: { type: GraphQLString },
2245
+ * },
2221
2246
  * });
2222
2247
  * ```
2223
2248
  */
@@ -2228,7 +2253,7 @@ class GraphQLInterfaceType {
2228
2253
 
2229
2254
  /** Function that resolves the concrete object type for this abstract type. */
2230
2255
 
2231
- /** Extension fields to include in the formatted result. */
2256
+ /** Custom extension fields reserved for users. */
2232
2257
 
2233
2258
  /** AST node from which this schema element was built, if available. */
2234
2259
 
@@ -2239,7 +2264,8 @@ class GraphQLInterfaceType {
2239
2264
  * @param config - Configuration describing this object.
2240
2265
  * @example
2241
2266
  * ```ts
2242
- * import { parse } from 'graphql/language';
2267
+ * import assert from 'node:assert/strict';
2268
+ * import { parse, Kind } from 'graphql/language';
2243
2269
  * import { GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from 'graphql/type';
2244
2270
  *
2245
2271
  * const document = parse(`
@@ -2255,6 +2281,8 @@ class GraphQLInterfaceType {
2255
2281
  * url: String
2256
2282
  * }
2257
2283
  * `);
2284
+ * assert(document.definitions[1].kind === Kind.INTERFACE_TYPE_DEFINITION);
2285
+ * assert(document.definitions[2].kind === Kind.INTERFACE_TYPE_EXTENSION);
2258
2286
  *
2259
2287
  * const Node = new GraphQLInterfaceType({
2260
2288
  * name: 'Node',
@@ -2273,11 +2301,11 @@ class GraphQLInterfaceType {
2273
2301
  * resolveType: (value) => {
2274
2302
  * return typeof value === 'object' && value != null && 'url' in value
2275
2303
  * ? 'WebPage'
2276
- * : null;
2304
+ * : undefined;
2277
2305
  * },
2278
2306
  * extensions: { abstract: true },
2279
2307
  * astNode: document.definitions[1],
2280
- * extensionASTNodes: [ document.definitions[2] ],
2308
+ * extensionASTNodes: [document.definitions[2]],
2281
2309
  * });
2282
2310
  *
2283
2311
  * Resource.name; // => 'Resource'
@@ -2497,17 +2525,30 @@ exports.GraphQLInterfaceType = GraphQLInterfaceType;
2497
2525
  * to determine which type is actually used when the field is resolved.
2498
2526
  * @example
2499
2527
  * ```ts
2528
+ * import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql';
2529
+ *
2530
+ * class Dog {}
2531
+ * class Cat {}
2532
+ * const DogType = new GraphQLObjectType({
2533
+ * name: 'Dog',
2534
+ * fields: { name: { type: GraphQLString } },
2535
+ * });
2536
+ * const CatType = new GraphQLObjectType({
2537
+ * name: 'Cat',
2538
+ * fields: { name: { type: GraphQLString } },
2539
+ * });
2540
+ *
2500
2541
  * const PetType = new GraphQLUnionType({
2501
2542
  * name: 'Pet',
2502
2543
  * types: [DogType, CatType],
2503
2544
  * resolveType: (value) => {
2504
2545
  * if (value instanceof Dog) {
2505
- * return DogType;
2546
+ * return 'Dog';
2506
2547
  * }
2507
2548
  * if (value instanceof Cat) {
2508
- * return CatType;
2549
+ * return 'Cat';
2509
2550
  * }
2510
- * }
2551
+ * },
2511
2552
  * });
2512
2553
  * ```
2513
2554
  */
@@ -2518,7 +2559,7 @@ class GraphQLUnionType {
2518
2559
 
2519
2560
  /** Function that resolves the concrete object type for this abstract type. */
2520
2561
 
2521
- /** Extension fields to include in the formatted result. */
2562
+ /** Custom extension fields reserved for users. */
2522
2563
 
2523
2564
  /** AST node from which this schema element was built, if available. */
2524
2565
 
@@ -2529,14 +2570,21 @@ class GraphQLUnionType {
2529
2570
  * @param config - Configuration describing this object.
2530
2571
  * @example
2531
2572
  * ```ts
2532
- * import { parse } from 'graphql/language';
2533
- * import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
2573
+ * import assert from 'node:assert/strict';
2574
+ * import { parse, Kind } from 'graphql/language';
2575
+ * import {
2576
+ * GraphQLObjectType,
2577
+ * GraphQLString,
2578
+ * GraphQLUnionType,
2579
+ * } from 'graphql/type';
2534
2580
  *
2535
2581
  * const document = parse(`
2536
2582
  * union Media = Photo | Video
2537
2583
  *
2538
2584
  * extend union Media = Audio
2539
2585
  * `);
2586
+ * assert(document.definitions[0].kind === Kind.UNION_TYPE_DEFINITION);
2587
+ * assert(document.definitions[1].kind === Kind.UNION_TYPE_EXTENSION);
2540
2588
  *
2541
2589
  * const Photo = new GraphQLObjectType({
2542
2590
  * name: 'Photo',
@@ -2558,7 +2606,7 @@ class GraphQLUnionType {
2558
2606
  * },
2559
2607
  * extensions: { searchable: true },
2560
2608
  * astNode: document.definitions[0],
2561
- * extensionASTNodes: [ document.definitions[1] ],
2609
+ * extensionASTNodes: [document.definitions[1]],
2562
2610
  * });
2563
2611
  *
2564
2612
  * Media.description; // => 'Media that can appear in a search result.'
@@ -2638,7 +2686,11 @@ class GraphQLUnionType {
2638
2686
  * @returns A configuration object that can be used to recreate this object.
2639
2687
  * @example
2640
2688
  * ```ts
2641
- * import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
2689
+ * import {
2690
+ * GraphQLObjectType,
2691
+ * GraphQLString,
2692
+ * GraphQLUnionType,
2693
+ * } from 'graphql/type';
2642
2694
  *
2643
2695
  * const Photo = new GraphQLObjectType({
2644
2696
  * name: 'Photo',
@@ -2705,7 +2757,11 @@ class GraphQLUnionType {
2705
2757
  * @returns The JSON-serializable representation.
2706
2758
  * @example
2707
2759
  * ```ts
2708
- * import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
2760
+ * import {
2761
+ * GraphQLObjectType,
2762
+ * GraphQLString,
2763
+ * GraphQLUnionType,
2764
+ * } from 'graphql/type';
2709
2765
  *
2710
2766
  * const Photo = new GraphQLObjectType({
2711
2767
  * name: 'Photo',
@@ -2774,7 +2830,7 @@ class GraphQLEnumType {
2774
2830
 
2775
2831
  /** Human-readable description for this schema element, if provided. */
2776
2832
 
2777
- /** Extension fields to include in the formatted result. */
2833
+ /** Custom extension fields reserved for users. */
2778
2834
 
2779
2835
  /** AST node from which this schema element was built, if available. */
2780
2836
 
@@ -2785,7 +2841,8 @@ class GraphQLEnumType {
2785
2841
  * @param config - Configuration describing this object.
2786
2842
  * @example
2787
2843
  * ```ts
2788
- * import { parse } from 'graphql/language';
2844
+ * import assert from 'node:assert/strict';
2845
+ * import { parse, Kind } from 'graphql/language';
2789
2846
  * import { GraphQLEnumType } from 'graphql/type';
2790
2847
  *
2791
2848
  * const document = parse(`
@@ -2799,6 +2856,8 @@ class GraphQLEnumType {
2799
2856
  * FORCE_AWAKENS
2800
2857
  * }
2801
2858
  * `);
2859
+ * assert(document.definitions[0].kind === Kind.ENUM_TYPE_DEFINITION);
2860
+ * assert(document.definitions[1].kind === Kind.ENUM_TYPE_EXTENSION);
2802
2861
  * const definition = document.definitions[0];
2803
2862
  *
2804
2863
  * const Episode = new GraphQLEnumType({
@@ -2809,24 +2868,24 @@ class GraphQLEnumType {
2809
2868
  * value: 4,
2810
2869
  * description: 'Released in 1977.',
2811
2870
  * extensions: { trilogy: 'original' },
2812
- * astNode: definition.values[0],
2871
+ * astNode: definition.values?.[0],
2813
2872
  * },
2814
- * EMPIRE: { value: 5, astNode: definition.values[1] },
2873
+ * EMPIRE: { value: 5, astNode: definition.values?.[1] },
2815
2874
  * JEDI: {
2816
2875
  * value: 6,
2817
2876
  * deprecationReason: 'Use RETURN_OF_THE_JEDI.',
2818
- * astNode: definition.values[2],
2877
+ * astNode: definition.values?.[2],
2819
2878
  * },
2820
2879
  * },
2821
2880
  * extensions: { catalog: 'films' },
2822
2881
  * astNode: definition,
2823
- * extensionASTNodes: [ document.definitions[1] ],
2882
+ * extensionASTNodes: [document.definitions[1]],
2824
2883
  * });
2825
2884
  *
2826
2885
  * Episode.description; // => 'A Star Wars film episode.'
2827
2886
  * Episode.serialize(5); // => 'EMPIRE'
2828
2887
  * Episode.parseValue('JEDI'); // => 6
2829
- * Episode.getValue('JEDI').deprecationReason; // => 'Use RETURN_OF_THE_JEDI.'
2888
+ * Episode.getValue('JEDI')?.deprecationReason; // => 'Use RETURN_OF_THE_JEDI.'
2830
2889
  * Episode.extensions; // => { catalog: 'films' }
2831
2890
  * ```
2832
2891
  */
@@ -2971,6 +3030,7 @@ class GraphQLEnumType {
2971
3030
  /**
2972
3031
  * Parses a GraphQL enum name from variable input.
2973
3032
  * @param inputValue - Runtime input value to parse.
3033
+ * @param hideSuggestions - Omit suggestions from error messages.
2974
3034
  * @returns The internal enum value represented by the input name.
2975
3035
  * @example
2976
3036
  * ```ts
@@ -2991,13 +3051,13 @@ class GraphQLEnumType {
2991
3051
  * ```
2992
3052
  */
2993
3053
 
2994
- parseValue(inputValue) /* T */
3054
+ parseValue(inputValue, hideSuggestions) /* T */
2995
3055
  {
2996
3056
  if (typeof inputValue !== 'string') {
2997
3057
  const valueStr = (0, _inspect.inspect)(inputValue);
2998
3058
  throw new _GraphQLError.GraphQLError(
2999
3059
  `Enum "${this.name}" cannot represent non-string value: ${valueStr}.` +
3000
- didYouMeanEnumValue(this, valueStr),
3060
+ (hideSuggestions ? '' : didYouMeanEnumValue(this, valueStr)),
3001
3061
  );
3002
3062
  }
3003
3063
 
@@ -3006,7 +3066,7 @@ class GraphQLEnumType {
3006
3066
  if (enumValue == null) {
3007
3067
  throw new _GraphQLError.GraphQLError(
3008
3068
  `Value "${inputValue}" does not exist in "${this.name}" enum.` +
3009
- didYouMeanEnumValue(this, inputValue),
3069
+ (hideSuggestions ? '' : didYouMeanEnumValue(this, inputValue)),
3010
3070
  );
3011
3071
  }
3012
3072
 
@@ -3016,6 +3076,7 @@ class GraphQLEnumType {
3016
3076
  * Parses a GraphQL enum name from an AST value literal.
3017
3077
  * @param valueNode - AST value literal to parse.
3018
3078
  * @param _variables - Runtime variable values; ignored because enum literals cannot contain variables.
3079
+ * @param hideSuggestions - Omit suggestions from error messages.
3019
3080
  * @returns The internal enum value represented by the literal.
3020
3081
  * @example
3021
3082
  * ```ts
@@ -3031,19 +3092,19 @@ class GraphQLEnumType {
3031
3092
  * },
3032
3093
  * });
3033
3094
  *
3034
- * RGB.parseLiteral(parseValue('RED')); // => 0
3035
- * RGB.parseLiteral(parseValue('"RED"')); // throws an error
3095
+ * RGB.parseLiteral(parseValue('RED'), undefined); // => 0
3096
+ * RGB.parseLiteral(parseValue('"RED"'), undefined); // throws an error
3036
3097
  * ```
3037
3098
  */
3038
3099
 
3039
- parseLiteral(valueNode, _variables) /* T */
3100
+ parseLiteral(valueNode, _variables, hideSuggestions) /* T */
3040
3101
  {
3041
3102
  // Note: variables will be resolved to a value before calling this function.
3042
3103
  if (valueNode.kind !== _kinds.Kind.ENUM) {
3043
- const valueStr = (0, _printer.print)(valueNode);
3104
+ const valueStr = (0, _printer.printForError)(valueNode);
3044
3105
  throw new _GraphQLError.GraphQLError(
3045
3106
  `Enum "${this.name}" cannot represent non-enum value: ${valueStr}.` +
3046
- didYouMeanEnumValue(this, valueStr),
3107
+ (hideSuggestions ? '' : didYouMeanEnumValue(this, valueStr)),
3047
3108
  {
3048
3109
  nodes: valueNode,
3049
3110
  },
@@ -3053,10 +3114,10 @@ class GraphQLEnumType {
3053
3114
  const enumValue = this.getValue(valueNode.value);
3054
3115
 
3055
3116
  if (enumValue == null) {
3056
- const valueStr = (0, _printer.print)(valueNode);
3117
+ const valueStr = (0, _printer.printForError)(valueNode);
3057
3118
  throw new _GraphQLError.GraphQLError(
3058
3119
  `Value "${valueStr}" does not exist in "${this.name}" enum.` +
3059
- didYouMeanEnumValue(this, valueStr),
3120
+ (hideSuggestions ? '' : didYouMeanEnumValue(this, valueStr)),
3060
3121
  {
3061
3122
  nodes: valueNode,
3062
3123
  },
@@ -3208,13 +3269,15 @@ function defineEnumValues(typeName, valueMap) {
3208
3269
  * Using `NonNull` will ensure that a value must be provided by the query
3209
3270
  * @example
3210
3271
  * ```ts
3272
+ * import { GraphQLFloat, GraphQLInputObjectType, GraphQLNonNull } from 'graphql';
3273
+ *
3211
3274
  * const GeoPoint = new GraphQLInputObjectType({
3212
3275
  * name: 'GeoPoint',
3213
3276
  * fields: {
3214
3277
  * lat: { type: new GraphQLNonNull(GraphQLFloat) },
3215
3278
  * lon: { type: new GraphQLNonNull(GraphQLFloat) },
3216
3279
  * alt: { type: GraphQLFloat, defaultValue: 0 },
3217
- * }
3280
+ * },
3218
3281
  * });
3219
3282
  * ```
3220
3283
  */
@@ -3223,7 +3286,7 @@ class GraphQLInputObjectType {
3223
3286
 
3224
3287
  /** Human-readable description for this schema element, if provided. */
3225
3288
 
3226
- /** Extension fields to include in the formatted result. */
3289
+ /** Custom extension fields reserved for users. */
3227
3290
 
3228
3291
  /** AST node from which this schema element was built, if available. */
3229
3292
 
@@ -3236,7 +3299,8 @@ class GraphQLInputObjectType {
3236
3299
  * @param config - Configuration describing this object.
3237
3300
  * @example
3238
3301
  * ```ts
3239
- * import { parse } from 'graphql/language';
3302
+ * import assert from 'node:assert/strict';
3303
+ * import { parse, Kind } from 'graphql/language';
3240
3304
  * import {
3241
3305
  * GraphQLID,
3242
3306
  * GraphQLInputObjectType,
@@ -3255,6 +3319,8 @@ class GraphQLInputObjectType {
3255
3319
  * body: String
3256
3320
  * }
3257
3321
  * `);
3322
+ * assert(document.definitions[0].kind === Kind.INPUT_OBJECT_TYPE_DEFINITION);
3323
+ * assert(document.definitions[1].kind === Kind.INPUT_OBJECT_TYPE_EXTENSION);
3258
3324
  * const definition = document.definitions[0];
3259
3325
  *
3260
3326
  * const ReviewInput = new GraphQLInputObjectType({
@@ -3265,18 +3331,18 @@ class GraphQLInputObjectType {
3265
3331
  * description: 'Star rating from one to five.',
3266
3332
  * type: new GraphQLNonNull(GraphQLInt),
3267
3333
  * extensions: { min: 1, max: 5 },
3268
- * astNode: definition.fields[0],
3334
+ * astNode: definition.fields?.[0],
3269
3335
  * },
3270
3336
  * commentary: {
3271
3337
  * type: GraphQLString,
3272
3338
  * defaultValue: '',
3273
3339
  * deprecationReason: 'Use body.',
3274
- * astNode: definition.fields[1],
3340
+ * astNode: definition.fields?.[1],
3275
3341
  * },
3276
3342
  * },
3277
3343
  * extensions: { form: 'review' },
3278
3344
  * astNode: definition,
3279
- * extensionASTNodes: [ document.definitions[1] ],
3345
+ * extensionASTNodes: [document.definitions[1]],
3280
3346
  * isOneOf: false,
3281
3347
  * });
3282
3348
  * const SearchBy = new GraphQLInputObjectType({
@@ -3490,19 +3556,26 @@ function defineInputFieldMap(config) {
3490
3556
  * @example
3491
3557
  * ```ts
3492
3558
  * import {
3559
+ * GraphQLInputObjectType,
3493
3560
  * GraphQLInt,
3494
3561
  * GraphQLNonNull,
3495
3562
  * GraphQLString,
3496
3563
  * isRequiredInputField,
3497
3564
  * } from 'graphql/type';
3498
3565
  *
3499
- * const requiredField = { name: 'id', type: new GraphQLNonNull(GraphQLInt) };
3500
- * const optionalField = { name: 'name', type: GraphQLString };
3501
- * const fieldWithDefault = {
3502
- * name: 'limit',
3503
- * type: new GraphQLNonNull(GraphQLInt),
3504
- * defaultValue: 10,
3505
- * };
3566
+ * const Input = new GraphQLInputObjectType({
3567
+ * name: 'Input',
3568
+ * fields: {
3569
+ * id: { type: new GraphQLNonNull(GraphQLInt) },
3570
+ * name: { type: GraphQLString },
3571
+ * limit: { type: new GraphQLNonNull(GraphQLInt), defaultValue: 10 },
3572
+ * },
3573
+ * });
3574
+ * const {
3575
+ * id: requiredField,
3576
+ * name: optionalField,
3577
+ * limit: fieldWithDefault,
3578
+ * } = Input.getFields();
3506
3579
  *
3507
3580
  * isRequiredInputField(requiredField); // => true
3508
3581
  * isRequiredInputField(optionalField); // => false