findBreakingChanges.js 21 KB

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