findBreakingChanges.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.findBreakingChanges = findBreakingChanges;
  6. exports.findDangerousChanges = findDangerousChanges;
  7. exports.DangerousChangeType = exports.BreakingChangeType = void 0;
  8. var _objectValues = _interopRequireDefault(require("../polyfills/objectValues.js"));
  9. var _keyMap = _interopRequireDefault(require("../jsutils/keyMap.js"));
  10. var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
  11. var _invariant = _interopRequireDefault(require("../jsutils/invariant.js"));
  12. var _naturalCompare = _interopRequireDefault(require("../jsutils/naturalCompare.js"));
  13. var _printer = require("../language/printer.js");
  14. var _visitor = require("../language/visitor.js");
  15. var _scalars = require("../type/scalars.js");
  16. var _definition = require("../type/definition.js");
  17. var _astFromValue = require("./astFromValue.js");
  18. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  19. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  20. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  21. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  22. var BreakingChangeType = Object.freeze({
  23. TYPE_REMOVED: 'TYPE_REMOVED',
  24. TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND',
  25. TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION',
  26. VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM',
  27. REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED',
  28. IMPLEMENTED_INTERFACE_REMOVED: 'IMPLEMENTED_INTERFACE_REMOVED',
  29. FIELD_REMOVED: 'FIELD_REMOVED',
  30. FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND',
  31. REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED',
  32. ARG_REMOVED: 'ARG_REMOVED',
  33. ARG_CHANGED_KIND: 'ARG_CHANGED_KIND',
  34. DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
  35. DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
  36. REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
  37. DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED',
  38. DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED'
  39. });
  40. exports.BreakingChangeType = BreakingChangeType;
  41. var DangerousChangeType = Object.freeze({
  42. VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM',
  43. TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION',
  44. OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED',
  45. OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED',
  46. IMPLEMENTED_INTERFACE_ADDED: 'IMPLEMENTED_INTERFACE_ADDED',
  47. ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE'
  48. });
  49. exports.DangerousChangeType = DangerousChangeType;
  50. /**
  51. * Given two schemas, returns an Array containing descriptions of all the types
  52. * of breaking changes covered by the other functions down below.
  53. */
  54. function findBreakingChanges(oldSchema, newSchema) {
  55. var breakingChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
  56. return change.type in BreakingChangeType;
  57. });
  58. return breakingChanges;
  59. }
  60. /**
  61. * Given two schemas, returns an Array containing descriptions of all the types
  62. * of potentially dangerous changes covered by the other functions down below.
  63. */
  64. function findDangerousChanges(oldSchema, newSchema) {
  65. var dangerousChanges = findSchemaChanges(oldSchema, newSchema).filter(function (change) {
  66. return change.type in DangerousChangeType;
  67. });
  68. return dangerousChanges;
  69. }
  70. function findSchemaChanges(oldSchema, newSchema) {
  71. return [].concat(findTypeChanges(oldSchema, newSchema), findDirectiveChanges(oldSchema, newSchema));
  72. }
  73. function findDirectiveChanges(oldSchema, newSchema) {
  74. var schemaChanges = [];
  75. var directivesDiff = diff(oldSchema.getDirectives(), newSchema.getDirectives());
  76. for (var _i2 = 0, _directivesDiff$remov2 = directivesDiff.removed; _i2 < _directivesDiff$remov2.length; _i2++) {
  77. var oldDirective = _directivesDiff$remov2[_i2];
  78. schemaChanges.push({
  79. type: BreakingChangeType.DIRECTIVE_REMOVED,
  80. description: "".concat(oldDirective.name, " was removed.")
  81. });
  82. }
  83. for (var _i4 = 0, _directivesDiff$persi2 = directivesDiff.persisted; _i4 < _directivesDiff$persi2.length; _i4++) {
  84. var _ref2 = _directivesDiff$persi2[_i4];
  85. var _oldDirective = _ref2[0];
  86. var newDirective = _ref2[1];
  87. var argsDiff = diff(_oldDirective.args, newDirective.args);
  88. for (var _i6 = 0, _argsDiff$added2 = argsDiff.added; _i6 < _argsDiff$added2.length; _i6++) {
  89. var newArg = _argsDiff$added2[_i6];
  90. if ((0, _definition.isRequiredArgument)(newArg)) {
  91. schemaChanges.push({
  92. type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
  93. description: "A required arg ".concat(newArg.name, " on directive ").concat(_oldDirective.name, " was added.")
  94. });
  95. }
  96. }
  97. for (var _i8 = 0, _argsDiff$removed2 = argsDiff.removed; _i8 < _argsDiff$removed2.length; _i8++) {
  98. var oldArg = _argsDiff$removed2[_i8];
  99. schemaChanges.push({
  100. type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
  101. description: "".concat(oldArg.name, " was removed from ").concat(_oldDirective.name, ".")
  102. });
  103. }
  104. if (_oldDirective.isRepeatable && !newDirective.isRepeatable) {
  105. schemaChanges.push({
  106. type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
  107. description: "Repeatable flag was removed from ".concat(_oldDirective.name, ".")
  108. });
  109. }
  110. for (var _i10 = 0, _oldDirective$locatio2 = _oldDirective.locations; _i10 < _oldDirective$locatio2.length; _i10++) {
  111. var location = _oldDirective$locatio2[_i10];
  112. if (newDirective.locations.indexOf(location) === -1) {
  113. schemaChanges.push({
  114. type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
  115. description: "".concat(location, " was removed from ").concat(_oldDirective.name, ".")
  116. });
  117. }
  118. }
  119. }
  120. return schemaChanges;
  121. }
  122. function findTypeChanges(oldSchema, newSchema) {
  123. var schemaChanges = [];
  124. var typesDiff = diff((0, _objectValues.default)(oldSchema.getTypeMap()), (0, _objectValues.default)(newSchema.getTypeMap()));
  125. for (var _i12 = 0, _typesDiff$removed2 = typesDiff.removed; _i12 < _typesDiff$removed2.length; _i12++) {
  126. var oldType = _typesDiff$removed2[_i12];
  127. schemaChanges.push({
  128. type: BreakingChangeType.TYPE_REMOVED,
  129. description: (0, _scalars.isSpecifiedScalarType)(oldType) ? "Standard scalar ".concat(oldType.name, " was removed because it is not referenced anymore.") : "".concat(oldType.name, " was removed.")
  130. });
  131. }
  132. for (var _i14 = 0, _typesDiff$persisted2 = typesDiff.persisted; _i14 < _typesDiff$persisted2.length; _i14++) {
  133. var _ref4 = _typesDiff$persisted2[_i14];
  134. var _oldType = _ref4[0];
  135. var newType = _ref4[1];
  136. if ((0, _definition.isEnumType)(_oldType) && (0, _definition.isEnumType)(newType)) {
  137. schemaChanges.push.apply(schemaChanges, findEnumTypeChanges(_oldType, newType));
  138. } else if ((0, _definition.isUnionType)(_oldType) && (0, _definition.isUnionType)(newType)) {
  139. schemaChanges.push.apply(schemaChanges, findUnionTypeChanges(_oldType, newType));
  140. } else if ((0, _definition.isInputObjectType)(_oldType) && (0, _definition.isInputObjectType)(newType)) {
  141. schemaChanges.push.apply(schemaChanges, findInputObjectTypeChanges(_oldType, newType));
  142. } else if ((0, _definition.isObjectType)(_oldType) && (0, _definition.isObjectType)(newType)) {
  143. schemaChanges.push.apply(schemaChanges, findFieldChanges(_oldType, newType).concat(findImplementedInterfacesChanges(_oldType, newType)));
  144. } else if ((0, _definition.isInterfaceType)(_oldType) && (0, _definition.isInterfaceType)(newType)) {
  145. schemaChanges.push.apply(schemaChanges, findFieldChanges(_oldType, newType).concat(findImplementedInterfacesChanges(_oldType, newType)));
  146. } else if (_oldType.constructor !== newType.constructor) {
  147. schemaChanges.push({
  148. type: BreakingChangeType.TYPE_CHANGED_KIND,
  149. description: "".concat(_oldType.name, " changed from ") + "".concat(typeKindName(_oldType), " to ").concat(typeKindName(newType), ".")
  150. });
  151. }
  152. }
  153. return schemaChanges;
  154. }
  155. function findInputObjectTypeChanges(oldType, newType) {
  156. var schemaChanges = [];
  157. var fieldsDiff = diff((0, _objectValues.default)(oldType.getFields()), (0, _objectValues.default)(newType.getFields()));
  158. for (var _i16 = 0, _fieldsDiff$added2 = fieldsDiff.added; _i16 < _fieldsDiff$added2.length; _i16++) {
  159. var newField = _fieldsDiff$added2[_i16];
  160. if ((0, _definition.isRequiredInputField)(newField)) {
  161. schemaChanges.push({
  162. type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
  163. description: "A required field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
  164. });
  165. } else {
  166. schemaChanges.push({
  167. type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
  168. description: "An optional field ".concat(newField.name, " on input type ").concat(oldType.name, " was added.")
  169. });
  170. }
  171. }
  172. for (var _i18 = 0, _fieldsDiff$removed2 = fieldsDiff.removed; _i18 < _fieldsDiff$removed2.length; _i18++) {
  173. var oldField = _fieldsDiff$removed2[_i18];
  174. schemaChanges.push({
  175. type: BreakingChangeType.FIELD_REMOVED,
  176. description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
  177. });
  178. }
  179. for (var _i20 = 0, _fieldsDiff$persisted2 = fieldsDiff.persisted; _i20 < _fieldsDiff$persisted2.length; _i20++) {
  180. var _ref6 = _fieldsDiff$persisted2[_i20];
  181. var _oldField = _ref6[0];
  182. var _newField = _ref6[1];
  183. var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldField.type, _newField.type);
  184. if (!isSafe) {
  185. schemaChanges.push({
  186. type: BreakingChangeType.FIELD_CHANGED_KIND,
  187. description: "".concat(oldType.name, ".").concat(_oldField.name, " changed type from ") + "".concat(String(_oldField.type), " to ").concat(String(_newField.type), ".")
  188. });
  189. }
  190. }
  191. return schemaChanges;
  192. }
  193. function findUnionTypeChanges(oldType, newType) {
  194. var schemaChanges = [];
  195. var possibleTypesDiff = diff(oldType.getTypes(), newType.getTypes());
  196. for (var _i22 = 0, _possibleTypesDiff$ad2 = possibleTypesDiff.added; _i22 < _possibleTypesDiff$ad2.length; _i22++) {
  197. var newPossibleType = _possibleTypesDiff$ad2[_i22];
  198. schemaChanges.push({
  199. type: DangerousChangeType.TYPE_ADDED_TO_UNION,
  200. description: "".concat(newPossibleType.name, " was added to union type ").concat(oldType.name, ".")
  201. });
  202. }
  203. for (var _i24 = 0, _possibleTypesDiff$re2 = possibleTypesDiff.removed; _i24 < _possibleTypesDiff$re2.length; _i24++) {
  204. var oldPossibleType = _possibleTypesDiff$re2[_i24];
  205. schemaChanges.push({
  206. type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
  207. description: "".concat(oldPossibleType.name, " was removed from union type ").concat(oldType.name, ".")
  208. });
  209. }
  210. return schemaChanges;
  211. }
  212. function findEnumTypeChanges(oldType, newType) {
  213. var schemaChanges = [];
  214. var valuesDiff = diff(oldType.getValues(), newType.getValues());
  215. for (var _i26 = 0, _valuesDiff$added2 = valuesDiff.added; _i26 < _valuesDiff$added2.length; _i26++) {
  216. var newValue = _valuesDiff$added2[_i26];
  217. schemaChanges.push({
  218. type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
  219. description: "".concat(newValue.name, " was added to enum type ").concat(oldType.name, ".")
  220. });
  221. }
  222. for (var _i28 = 0, _valuesDiff$removed2 = valuesDiff.removed; _i28 < _valuesDiff$removed2.length; _i28++) {
  223. var oldValue = _valuesDiff$removed2[_i28];
  224. schemaChanges.push({
  225. type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
  226. description: "".concat(oldValue.name, " was removed from enum type ").concat(oldType.name, ".")
  227. });
  228. }
  229. return schemaChanges;
  230. }
  231. function findImplementedInterfacesChanges(oldType, newType) {
  232. var schemaChanges = [];
  233. var interfacesDiff = diff(oldType.getInterfaces(), newType.getInterfaces());
  234. for (var _i30 = 0, _interfacesDiff$added2 = interfacesDiff.added; _i30 < _interfacesDiff$added2.length; _i30++) {
  235. var newInterface = _interfacesDiff$added2[_i30];
  236. schemaChanges.push({
  237. type: DangerousChangeType.IMPLEMENTED_INTERFACE_ADDED,
  238. description: "".concat(newInterface.name, " added to interfaces implemented by ").concat(oldType.name, ".")
  239. });
  240. }
  241. for (var _i32 = 0, _interfacesDiff$remov2 = interfacesDiff.removed; _i32 < _interfacesDiff$remov2.length; _i32++) {
  242. var oldInterface = _interfacesDiff$remov2[_i32];
  243. schemaChanges.push({
  244. type: BreakingChangeType.IMPLEMENTED_INTERFACE_REMOVED,
  245. description: "".concat(oldType.name, " no longer implements interface ").concat(oldInterface.name, ".")
  246. });
  247. }
  248. return schemaChanges;
  249. }
  250. function findFieldChanges(oldType, newType) {
  251. var schemaChanges = [];
  252. var fieldsDiff = diff((0, _objectValues.default)(oldType.getFields()), (0, _objectValues.default)(newType.getFields()));
  253. for (var _i34 = 0, _fieldsDiff$removed4 = fieldsDiff.removed; _i34 < _fieldsDiff$removed4.length; _i34++) {
  254. var oldField = _fieldsDiff$removed4[_i34];
  255. schemaChanges.push({
  256. type: BreakingChangeType.FIELD_REMOVED,
  257. description: "".concat(oldType.name, ".").concat(oldField.name, " was removed.")
  258. });
  259. }
  260. for (var _i36 = 0, _fieldsDiff$persisted4 = fieldsDiff.persisted; _i36 < _fieldsDiff$persisted4.length; _i36++) {
  261. var _ref8 = _fieldsDiff$persisted4[_i36];
  262. var _oldField2 = _ref8[0];
  263. var newField = _ref8[1];
  264. schemaChanges.push.apply(schemaChanges, findArgChanges(oldType, _oldField2, newField));
  265. var isSafe = isChangeSafeForObjectOrInterfaceField(_oldField2.type, newField.type);
  266. if (!isSafe) {
  267. schemaChanges.push({
  268. type: BreakingChangeType.FIELD_CHANGED_KIND,
  269. description: "".concat(oldType.name, ".").concat(_oldField2.name, " changed type from ") + "".concat(String(_oldField2.type), " to ").concat(String(newField.type), ".")
  270. });
  271. }
  272. }
  273. return schemaChanges;
  274. }
  275. function findArgChanges(oldType, oldField, newField) {
  276. var schemaChanges = [];
  277. var argsDiff = diff(oldField.args, newField.args);
  278. for (var _i38 = 0, _argsDiff$removed4 = argsDiff.removed; _i38 < _argsDiff$removed4.length; _i38++) {
  279. var oldArg = _argsDiff$removed4[_i38];
  280. schemaChanges.push({
  281. type: BreakingChangeType.ARG_REMOVED,
  282. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(oldArg.name, " was removed.")
  283. });
  284. }
  285. for (var _i40 = 0, _argsDiff$persisted2 = argsDiff.persisted; _i40 < _argsDiff$persisted2.length; _i40++) {
  286. var _ref10 = _argsDiff$persisted2[_i40];
  287. var _oldArg = _ref10[0];
  288. var newArg = _ref10[1];
  289. var isSafe = isChangeSafeForInputObjectFieldOrFieldArg(_oldArg.type, newArg.type);
  290. if (!isSafe) {
  291. schemaChanges.push({
  292. type: BreakingChangeType.ARG_CHANGED_KIND,
  293. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed type from ") + "".concat(String(_oldArg.type), " to ").concat(String(newArg.type), ".")
  294. });
  295. } else if (_oldArg.defaultValue !== undefined) {
  296. if (newArg.defaultValue === undefined) {
  297. schemaChanges.push({
  298. type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
  299. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " defaultValue was removed.")
  300. });
  301. } else {
  302. // Since we looking only for client's observable changes we should
  303. // compare default values in the same representation as they are
  304. // represented inside introspection.
  305. var oldValueStr = stringifyValue(_oldArg.defaultValue, _oldArg.type);
  306. var newValueStr = stringifyValue(newArg.defaultValue, newArg.type);
  307. if (oldValueStr !== newValueStr) {
  308. schemaChanges.push({
  309. type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
  310. description: "".concat(oldType.name, ".").concat(oldField.name, " arg ").concat(_oldArg.name, " has changed defaultValue from ").concat(oldValueStr, " to ").concat(newValueStr, ".")
  311. });
  312. }
  313. }
  314. }
  315. }
  316. for (var _i42 = 0, _argsDiff$added4 = argsDiff.added; _i42 < _argsDiff$added4.length; _i42++) {
  317. var _newArg = _argsDiff$added4[_i42];
  318. if ((0, _definition.isRequiredArgument)(_newArg)) {
  319. schemaChanges.push({
  320. type: BreakingChangeType.REQUIRED_ARG_ADDED,
  321. description: "A required arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
  322. });
  323. } else {
  324. schemaChanges.push({
  325. type: DangerousChangeType.OPTIONAL_ARG_ADDED,
  326. description: "An optional arg ".concat(_newArg.name, " on ").concat(oldType.name, ".").concat(oldField.name, " was added.")
  327. });
  328. }
  329. }
  330. return schemaChanges;
  331. }
  332. function isChangeSafeForObjectOrInterfaceField(oldType, newType) {
  333. if ((0, _definition.isListType)(oldType)) {
  334. return (// if they're both lists, make sure the underlying types are compatible
  335. (0, _definition.isListType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType) || // moving from nullable to non-null of the same underlying type is safe
  336. (0, _definition.isNonNullType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
  337. );
  338. }
  339. if ((0, _definition.isNonNullType)(oldType)) {
  340. // if they're both non-null, make sure the underlying types are compatible
  341. return (0, _definition.isNonNullType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType);
  342. }
  343. return (// if they're both named types, see if their names are equivalent
  344. (0, _definition.isNamedType)(newType) && oldType.name === newType.name || // moving from nullable to non-null of the same underlying type is safe
  345. (0, _definition.isNonNullType)(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)
  346. );
  347. }
  348. function isChangeSafeForInputObjectFieldOrFieldArg(oldType, newType) {
  349. if ((0, _definition.isListType)(oldType)) {
  350. // if they're both lists, make sure the underlying types are compatible
  351. return (0, _definition.isListType)(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType);
  352. }
  353. if ((0, _definition.isNonNullType)(oldType)) {
  354. return (// if they're both non-null, make sure the underlying types are
  355. // compatible
  356. (0, _definition.isNonNullType)(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType) || // moving from non-null to nullable of the same underlying type is safe
  357. !(0, _definition.isNonNullType)(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType)
  358. );
  359. } // if they're both named types, see if their names are equivalent
  360. return (0, _definition.isNamedType)(newType) && oldType.name === newType.name;
  361. }
  362. function typeKindName(type) {
  363. if ((0, _definition.isScalarType)(type)) {
  364. return 'a Scalar type';
  365. }
  366. if ((0, _definition.isObjectType)(type)) {
  367. return 'an Object type';
  368. }
  369. if ((0, _definition.isInterfaceType)(type)) {
  370. return 'an Interface type';
  371. }
  372. if ((0, _definition.isUnionType)(type)) {
  373. return 'a Union type';
  374. }
  375. if ((0, _definition.isEnumType)(type)) {
  376. return 'an Enum type';
  377. } // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
  378. if ((0, _definition.isInputObjectType)(type)) {
  379. return 'an Input type';
  380. } // istanbul ignore next (Not reachable. All possible named types have been considered)
  381. false || (0, _invariant.default)(0, 'Unexpected type: ' + (0, _inspect.default)(type));
  382. }
  383. function stringifyValue(value, type) {
  384. var ast = (0, _astFromValue.astFromValue)(value, type);
  385. ast != null || (0, _invariant.default)(0);
  386. var sortedAST = (0, _visitor.visit)(ast, {
  387. ObjectValue: function ObjectValue(objectNode) {
  388. // Make a copy since sort mutates array
  389. var fields = [].concat(objectNode.fields);
  390. fields.sort(function (fieldA, fieldB) {
  391. return (0, _naturalCompare.default)(fieldA.name.value, fieldB.name.value);
  392. });
  393. return _objectSpread(_objectSpread({}, objectNode), {}, {
  394. fields: fields
  395. });
  396. }
  397. });
  398. return (0, _printer.print)(sortedAST);
  399. }
  400. function diff(oldArray, newArray) {
  401. var added = [];
  402. var removed = [];
  403. var persisted = [];
  404. var oldMap = (0, _keyMap.default)(oldArray, function (_ref11) {
  405. var name = _ref11.name;
  406. return name;
  407. });
  408. var newMap = (0, _keyMap.default)(newArray, function (_ref12) {
  409. var name = _ref12.name;
  410. return name;
  411. });
  412. for (var _i44 = 0; _i44 < oldArray.length; _i44++) {
  413. var oldItem = oldArray[_i44];
  414. var newItem = newMap[oldItem.name];
  415. if (newItem === undefined) {
  416. removed.push(oldItem);
  417. } else {
  418. persisted.push([oldItem, newItem]);
  419. }
  420. }
  421. for (var _i46 = 0; _i46 < newArray.length; _i46++) {
  422. var _newItem = newArray[_i46];
  423. if (oldMap[_newItem.name] === undefined) {
  424. added.push(_newItem);
  425. }
  426. }
  427. return {
  428. added: added,
  429. persisted: persisted,
  430. removed: removed
  431. };
  432. }