findBreakingChanges.js 21 KB

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