subscription-transport-ws-client.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. var SubscriptionsTransportWs =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ i: moduleId,
  13. /******/ l: false,
  14. /******/ exports: {}
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.l = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // identity function for calling harmony imports with the correct context
  28. /******/ __webpack_require__.i = function(value) { return value; };
  29. /******/ // define getter function for harmony exports
  30. /******/ __webpack_require__.d = function(exports, name, getter) {
  31. /******/ if(!__webpack_require__.o(exports, name)) {
  32. /******/ Object.defineProperty(exports, name, {
  33. /******/ configurable: false,
  34. /******/ enumerable: true,
  35. /******/ get: getter
  36. /******/ });
  37. /******/ }
  38. /******/ };
  39. /******/ // getDefaultExport function for compatibility with non-harmony modules
  40. /******/ __webpack_require__.n = function(module) {
  41. /******/ var getter = module && module.__esModule ?
  42. /******/ function getDefault() { return module['default']; } :
  43. /******/ function getModuleExports() { return module; };
  44. /******/ __webpack_require__.d(getter, 'a', getter);
  45. /******/ return getter;
  46. /******/ };
  47. /******/ // Object.prototype.hasOwnProperty.call
  48. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  49. /******/ // __webpack_public_path__
  50. /******/ __webpack_require__.p = "";
  51. /******/ // Load entry module and return exports
  52. /******/ return __webpack_require__(__webpack_require__.s = 9);
  53. /******/ })
  54. /************************************************************************/
  55. /******/ ([
  56. /* 0 */
  57. /***/ (function(module, exports, __webpack_require__) {
  58. "use strict";
  59. var printer_1 = __webpack_require__(8);
  60. function addGraphQLSubscriptions(networkInterface, wsClient) {
  61. return Object.assign(networkInterface, {
  62. subscribe: function (request, handler) {
  63. return wsClient.subscribe({
  64. query: printer_1.print(request.query),
  65. variables: request.variables,
  66. }, handler);
  67. },
  68. unsubscribe: function (id) {
  69. wsClient.unsubscribe(id);
  70. },
  71. });
  72. }
  73. exports.addGraphQLSubscriptions = addGraphQLSubscriptions;
  74. //# sourceMappingURL=helpers.js.map
  75. /***/ }),
  76. /* 1 */
  77. /***/ (function(module, exports, __webpack_require__) {
  78. "use strict";
  79. var SUBSCRIPTION_FAIL = 'subscription_fail';
  80. exports.SUBSCRIPTION_FAIL = SUBSCRIPTION_FAIL;
  81. var SUBSCRIPTION_END = 'subscription_end';
  82. exports.SUBSCRIPTION_END = SUBSCRIPTION_END;
  83. var SUBSCRIPTION_DATA = 'subscription_data';
  84. exports.SUBSCRIPTION_DATA = SUBSCRIPTION_DATA;
  85. var SUBSCRIPTION_START = 'subscription_start';
  86. exports.SUBSCRIPTION_START = SUBSCRIPTION_START;
  87. var SUBSCRIPTION_SUCCESS = 'subscription_success';
  88. exports.SUBSCRIPTION_SUCCESS = SUBSCRIPTION_SUCCESS;
  89. var KEEPALIVE = 'keepalive';
  90. exports.KEEPALIVE = KEEPALIVE;
  91. var INIT = 'init';
  92. exports.INIT = INIT;
  93. var INIT_SUCCESS = 'init_success';
  94. exports.INIT_SUCCESS = INIT_SUCCESS;
  95. var INIT_FAIL = 'init_fail';
  96. exports.INIT_FAIL = INIT_FAIL;
  97. //# sourceMappingURL=messageTypes.js.map
  98. /***/ }),
  99. /* 2 */
  100. /***/ (function(module, exports, __webpack_require__) {
  101. "use strict";
  102. var GRAPHQL_SUBSCRIPTIONS = 'graphql-subscriptions';
  103. exports.GRAPHQL_SUBSCRIPTIONS = GRAPHQL_SUBSCRIPTIONS;
  104. //# sourceMappingURL=protocols.js.map
  105. /***/ }),
  106. /* 3 */
  107. /***/ (function(module, exports) {
  108. /**
  109. * Expose `Backoff`.
  110. */
  111. module.exports = Backoff;
  112. /**
  113. * Initialize backoff timer with `opts`.
  114. *
  115. * - `min` initial timeout in milliseconds [100]
  116. * - `max` max timeout [10000]
  117. * - `jitter` [0]
  118. * - `factor` [2]
  119. *
  120. * @param {Object} opts
  121. * @api public
  122. */
  123. function Backoff(opts) {
  124. opts = opts || {};
  125. this.ms = opts.min || 100;
  126. this.max = opts.max || 10000;
  127. this.factor = opts.factor || 2;
  128. this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
  129. this.attempts = 0;
  130. }
  131. /**
  132. * Return the backoff duration.
  133. *
  134. * @return {Number}
  135. * @api public
  136. */
  137. Backoff.prototype.duration = function(){
  138. var ms = this.ms * Math.pow(this.factor, this.attempts++);
  139. if (this.jitter) {
  140. var rand = Math.random();
  141. var deviation = Math.floor(rand * this.jitter * ms);
  142. ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
  143. }
  144. return Math.min(ms, this.max) | 0;
  145. };
  146. /**
  147. * Reset the number of attempts.
  148. *
  149. * @api public
  150. */
  151. Backoff.prototype.reset = function(){
  152. this.attempts = 0;
  153. };
  154. /**
  155. * Set the minimum duration
  156. *
  157. * @api public
  158. */
  159. Backoff.prototype.setMin = function(min){
  160. this.ms = min;
  161. };
  162. /**
  163. * Set the maximum duration
  164. *
  165. * @api public
  166. */
  167. Backoff.prototype.setMax = function(max){
  168. this.max = max;
  169. };
  170. /**
  171. * Set the jitter
  172. *
  173. * @api public
  174. */
  175. Backoff.prototype.setJitter = function(jitter){
  176. this.jitter = jitter;
  177. };
  178. /***/ }),
  179. /* 4 */
  180. /***/ (function(module, exports, __webpack_require__) {
  181. "use strict";
  182. var has = Object.prototype.hasOwnProperty
  183. , prefix = '~';
  184. /**
  185. * Constructor to create a storage for our `EE` objects.
  186. * An `Events` instance is a plain object whose properties are event names.
  187. *
  188. * @constructor
  189. * @api private
  190. */
  191. function Events() {}
  192. //
  193. // We try to not inherit from `Object.prototype`. In some engines creating an
  194. // instance in this way is faster than calling `Object.create(null)` directly.
  195. // If `Object.create(null)` is not supported we prefix the event names with a
  196. // character to make sure that the built-in object properties are not
  197. // overridden or used as an attack vector.
  198. //
  199. if (Object.create) {
  200. Events.prototype = Object.create(null);
  201. //
  202. // This hack is needed because the `__proto__` property is still inherited in
  203. // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
  204. //
  205. if (!new Events().__proto__) prefix = false;
  206. }
  207. /**
  208. * Representation of a single event listener.
  209. *
  210. * @param {Function} fn The listener function.
  211. * @param {Mixed} context The context to invoke the listener with.
  212. * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
  213. * @constructor
  214. * @api private
  215. */
  216. function EE(fn, context, once) {
  217. this.fn = fn;
  218. this.context = context;
  219. this.once = once || false;
  220. }
  221. /**
  222. * Minimal `EventEmitter` interface that is molded against the Node.js
  223. * `EventEmitter` interface.
  224. *
  225. * @constructor
  226. * @api public
  227. */
  228. function EventEmitter() {
  229. this._events = new Events();
  230. this._eventsCount = 0;
  231. }
  232. /**
  233. * Return an array listing the events for which the emitter has registered
  234. * listeners.
  235. *
  236. * @returns {Array}
  237. * @api public
  238. */
  239. EventEmitter.prototype.eventNames = function eventNames() {
  240. var names = []
  241. , events
  242. , name;
  243. if (this._eventsCount === 0) return names;
  244. for (name in (events = this._events)) {
  245. if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
  246. }
  247. if (Object.getOwnPropertySymbols) {
  248. return names.concat(Object.getOwnPropertySymbols(events));
  249. }
  250. return names;
  251. };
  252. /**
  253. * Return the listeners registered for a given event.
  254. *
  255. * @param {String|Symbol} event The event name.
  256. * @param {Boolean} exists Only check if there are listeners.
  257. * @returns {Array|Boolean}
  258. * @api public
  259. */
  260. EventEmitter.prototype.listeners = function listeners(event, exists) {
  261. var evt = prefix ? prefix + event : event
  262. , available = this._events[evt];
  263. if (exists) return !!available;
  264. if (!available) return [];
  265. if (available.fn) return [available.fn];
  266. for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) {
  267. ee[i] = available[i].fn;
  268. }
  269. return ee;
  270. };
  271. /**
  272. * Calls each of the listeners registered for a given event.
  273. *
  274. * @param {String|Symbol} event The event name.
  275. * @returns {Boolean} `true` if the event had listeners, else `false`.
  276. * @api public
  277. */
  278. EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
  279. var evt = prefix ? prefix + event : event;
  280. if (!this._events[evt]) return false;
  281. var listeners = this._events[evt]
  282. , len = arguments.length
  283. , args
  284. , i;
  285. if (listeners.fn) {
  286. if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
  287. switch (len) {
  288. case 1: return listeners.fn.call(listeners.context), true;
  289. case 2: return listeners.fn.call(listeners.context, a1), true;
  290. case 3: return listeners.fn.call(listeners.context, a1, a2), true;
  291. case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
  292. case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
  293. case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
  294. }
  295. for (i = 1, args = new Array(len -1); i < len; i++) {
  296. args[i - 1] = arguments[i];
  297. }
  298. listeners.fn.apply(listeners.context, args);
  299. } else {
  300. var length = listeners.length
  301. , j;
  302. for (i = 0; i < length; i++) {
  303. if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
  304. switch (len) {
  305. case 1: listeners[i].fn.call(listeners[i].context); break;
  306. case 2: listeners[i].fn.call(listeners[i].context, a1); break;
  307. case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
  308. case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
  309. default:
  310. if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
  311. args[j - 1] = arguments[j];
  312. }
  313. listeners[i].fn.apply(listeners[i].context, args);
  314. }
  315. }
  316. }
  317. return true;
  318. };
  319. /**
  320. * Add a listener for a given event.
  321. *
  322. * @param {String|Symbol} event The event name.
  323. * @param {Function} fn The listener function.
  324. * @param {Mixed} [context=this] The context to invoke the listener with.
  325. * @returns {EventEmitter} `this`.
  326. * @api public
  327. */
  328. EventEmitter.prototype.on = function on(event, fn, context) {
  329. var listener = new EE(fn, context || this)
  330. , evt = prefix ? prefix + event : event;
  331. if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++;
  332. else if (!this._events[evt].fn) this._events[evt].push(listener);
  333. else this._events[evt] = [this._events[evt], listener];
  334. return this;
  335. };
  336. /**
  337. * Add a one-time listener for a given event.
  338. *
  339. * @param {String|Symbol} event The event name.
  340. * @param {Function} fn The listener function.
  341. * @param {Mixed} [context=this] The context to invoke the listener with.
  342. * @returns {EventEmitter} `this`.
  343. * @api public
  344. */
  345. EventEmitter.prototype.once = function once(event, fn, context) {
  346. var listener = new EE(fn, context || this, true)
  347. , evt = prefix ? prefix + event : event;
  348. if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++;
  349. else if (!this._events[evt].fn) this._events[evt].push(listener);
  350. else this._events[evt] = [this._events[evt], listener];
  351. return this;
  352. };
  353. /**
  354. * Remove the listeners of a given event.
  355. *
  356. * @param {String|Symbol} event The event name.
  357. * @param {Function} fn Only remove the listeners that match this function.
  358. * @param {Mixed} context Only remove the listeners that have this context.
  359. * @param {Boolean} once Only remove one-time listeners.
  360. * @returns {EventEmitter} `this`.
  361. * @api public
  362. */
  363. EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
  364. var evt = prefix ? prefix + event : event;
  365. if (!this._events[evt]) return this;
  366. if (!fn) {
  367. if (--this._eventsCount === 0) this._events = new Events();
  368. else delete this._events[evt];
  369. return this;
  370. }
  371. var listeners = this._events[evt];
  372. if (listeners.fn) {
  373. if (
  374. listeners.fn === fn
  375. && (!once || listeners.once)
  376. && (!context || listeners.context === context)
  377. ) {
  378. if (--this._eventsCount === 0) this._events = new Events();
  379. else delete this._events[evt];
  380. }
  381. } else {
  382. for (var i = 0, events = [], length = listeners.length; i < length; i++) {
  383. if (
  384. listeners[i].fn !== fn
  385. || (once && !listeners[i].once)
  386. || (context && listeners[i].context !== context)
  387. ) {
  388. events.push(listeners[i]);
  389. }
  390. }
  391. //
  392. // Reset the array, or remove it completely if we have no more listeners.
  393. //
  394. if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
  395. else if (--this._eventsCount === 0) this._events = new Events();
  396. else delete this._events[evt];
  397. }
  398. return this;
  399. };
  400. /**
  401. * Remove all listeners, or those of the specified event.
  402. *
  403. * @param {String|Symbol} [event] The event name.
  404. * @returns {EventEmitter} `this`.
  405. * @api public
  406. */
  407. EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
  408. var evt;
  409. if (event) {
  410. evt = prefix ? prefix + event : event;
  411. if (this._events[evt]) {
  412. if (--this._eventsCount === 0) this._events = new Events();
  413. else delete this._events[evt];
  414. }
  415. } else {
  416. this._events = new Events();
  417. this._eventsCount = 0;
  418. }
  419. return this;
  420. };
  421. //
  422. // Alias methods names because people roll like that.
  423. //
  424. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  425. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  426. //
  427. // This function doesn't apply anymore.
  428. //
  429. EventEmitter.prototype.setMaxListeners = function setMaxListeners() {
  430. return this;
  431. };
  432. //
  433. // Expose the prefix.
  434. //
  435. EventEmitter.prefixed = prefix;
  436. //
  437. // Allow `EventEmitter` to be imported as module namespace.
  438. //
  439. EventEmitter.EventEmitter = EventEmitter;
  440. //
  441. // Expose the module.
  442. //
  443. if (true) {
  444. module.exports = EventEmitter;
  445. }
  446. /***/ }),
  447. /* 5 */
  448. /***/ (function(module, exports) {
  449. /**
  450. * lodash 3.0.2 (Custom Build) <https://lodash.com/>
  451. * Build: `lodash modern modularize exports="npm" -o ./`
  452. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  453. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  454. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  455. * Available under MIT license <https://lodash.com/license>
  456. */
  457. /**
  458. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  459. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  460. *
  461. * @static
  462. * @memberOf _
  463. * @category Lang
  464. * @param {*} value The value to check.
  465. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  466. * @example
  467. *
  468. * _.isObject({});
  469. * // => true
  470. *
  471. * _.isObject([1, 2, 3]);
  472. * // => true
  473. *
  474. * _.isObject(1);
  475. * // => false
  476. */
  477. function isObject(value) {
  478. // Avoid a V8 JIT bug in Chrome 19-20.
  479. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  480. var type = typeof value;
  481. return !!value && (type == 'object' || type == 'function');
  482. }
  483. module.exports = isObject;
  484. /***/ }),
  485. /* 6 */
  486. /***/ (function(module, exports) {
  487. /**
  488. * lodash 4.0.1 (Custom Build) <https://lodash.com/>
  489. * Build: `lodash modularize exports="npm" -o ./`
  490. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  491. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  492. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  493. * Available under MIT license <https://lodash.com/license>
  494. */
  495. /** `Object#toString` result references. */
  496. var stringTag = '[object String]';
  497. /** Used for built-in method references. */
  498. var objectProto = Object.prototype;
  499. /**
  500. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  501. * of values.
  502. */
  503. var objectToString = objectProto.toString;
  504. /**
  505. * Checks if `value` is classified as an `Array` object.
  506. *
  507. * @static
  508. * @memberOf _
  509. * @type Function
  510. * @category Lang
  511. * @param {*} value The value to check.
  512. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  513. * @example
  514. *
  515. * _.isArray([1, 2, 3]);
  516. * // => true
  517. *
  518. * _.isArray(document.body.children);
  519. * // => false
  520. *
  521. * _.isArray('abc');
  522. * // => false
  523. *
  524. * _.isArray(_.noop);
  525. * // => false
  526. */
  527. var isArray = Array.isArray;
  528. /**
  529. * Checks if `value` is object-like. A value is object-like if it's not `null`
  530. * and has a `typeof` result of "object".
  531. *
  532. * @static
  533. * @memberOf _
  534. * @category Lang
  535. * @param {*} value The value to check.
  536. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  537. * @example
  538. *
  539. * _.isObjectLike({});
  540. * // => true
  541. *
  542. * _.isObjectLike([1, 2, 3]);
  543. * // => true
  544. *
  545. * _.isObjectLike(_.noop);
  546. * // => false
  547. *
  548. * _.isObjectLike(null);
  549. * // => false
  550. */
  551. function isObjectLike(value) {
  552. return !!value && typeof value == 'object';
  553. }
  554. /**
  555. * Checks if `value` is classified as a `String` primitive or object.
  556. *
  557. * @static
  558. * @memberOf _
  559. * @category Lang
  560. * @param {*} value The value to check.
  561. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  562. * @example
  563. *
  564. * _.isString('abc');
  565. * // => true
  566. *
  567. * _.isString(1);
  568. * // => false
  569. */
  570. function isString(value) {
  571. return typeof value == 'string' ||
  572. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  573. }
  574. module.exports = isString;
  575. /***/ }),
  576. /* 7 */
  577. /***/ (function(module, exports) {
  578. var g;
  579. // This works in non-strict mode
  580. g = (function() {
  581. return this;
  582. })();
  583. try {
  584. // This works if eval is allowed (see CSP)
  585. g = g || Function("return this")() || (1,eval)("this");
  586. } catch(e) {
  587. // This works if the window reference is available
  588. if(typeof window === "object")
  589. g = window;
  590. }
  591. // g can still be undefined, but nothing to do about it...
  592. // We return undefined, instead of nothing here, so it's
  593. // easier to handle this case. if(!global) { ...}
  594. module.exports = g;
  595. /***/ }),
  596. /* 8 */
  597. /***/ (function(module, exports) {
  598. module.exports =
  599. /******/ (function(modules) { // webpackBootstrap
  600. /******/ // The module cache
  601. /******/ var installedModules = {};
  602. /******/ // The require function
  603. /******/ function __webpack_require__(moduleId) {
  604. /******/ // Check if module is in cache
  605. /******/ if(installedModules[moduleId])
  606. /******/ return installedModules[moduleId].exports;
  607. /******/ // Create a new module (and put it into the cache)
  608. /******/ var module = installedModules[moduleId] = {
  609. /******/ exports: {},
  610. /******/ id: moduleId,
  611. /******/ loaded: false
  612. /******/ };
  613. /******/ // Execute the module function
  614. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  615. /******/ // Flag the module as loaded
  616. /******/ module.loaded = true;
  617. /******/ // Return the exports of the module
  618. /******/ return module.exports;
  619. /******/ }
  620. /******/ // expose the modules object (__webpack_modules__)
  621. /******/ __webpack_require__.m = modules;
  622. /******/ // expose the module cache
  623. /******/ __webpack_require__.c = installedModules;
  624. /******/ // __webpack_public_path__
  625. /******/ __webpack_require__.p = "";
  626. /******/ // Load entry module and return exports
  627. /******/ return __webpack_require__(0);
  628. /******/ })
  629. /************************************************************************/
  630. /******/ ([
  631. /* 0 */
  632. /***/ function(module, exports, __webpack_require__) {
  633. module.exports = __webpack_require__(1);
  634. /***/ },
  635. /* 1 */
  636. /***/ function(module, exports, __webpack_require__) {
  637. 'use strict';
  638. Object.defineProperty(exports, "__esModule", {
  639. value: true
  640. });
  641. exports.print = print;
  642. var _visitor = __webpack_require__(2);
  643. /**
  644. * Converts an AST into a string, using one set of reasonable
  645. * formatting rules.
  646. */
  647. function print(ast) {
  648. return (0, _visitor.visit)(ast, { leave: printDocASTReducer });
  649. } /**
  650. * Copyright (c) 2015, Facebook, Inc.
  651. * All rights reserved.
  652. *
  653. * This source code is licensed under the BSD-style license found in the
  654. * LICENSE file in the root directory of this source tree. An additional grant
  655. * of patent rights can be found in the PATENTS file in the same directory.
  656. */
  657. var printDocASTReducer = {
  658. Name: function Name(node) {
  659. return node.value;
  660. },
  661. Variable: function Variable(node) {
  662. return '$' + node.name;
  663. },
  664. // Document
  665. Document: function Document(node) {
  666. return join(node.definitions, '\n\n') + '\n';
  667. },
  668. OperationDefinition: function OperationDefinition(node) {
  669. var op = node.operation;
  670. var name = node.name;
  671. var varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
  672. var directives = join(node.directives, ' ');
  673. var selectionSet = node.selectionSet;
  674. // Anonymous queries with no directives or variable definitions can use
  675. // the query short form.
  676. return !name && !directives && !varDefs && op === 'query' ? selectionSet : join([op, join([name, varDefs]), directives, selectionSet], ' ');
  677. },
  678. VariableDefinition: function VariableDefinition(_ref) {
  679. var variable = _ref.variable;
  680. var type = _ref.type;
  681. var defaultValue = _ref.defaultValue;
  682. return variable + ': ' + type + wrap(' = ', defaultValue);
  683. },
  684. SelectionSet: function SelectionSet(_ref2) {
  685. var selections = _ref2.selections;
  686. return block(selections);
  687. },
  688. Field: function Field(_ref3) {
  689. var alias = _ref3.alias;
  690. var name = _ref3.name;
  691. var args = _ref3.arguments;
  692. var directives = _ref3.directives;
  693. var selectionSet = _ref3.selectionSet;
  694. return join([wrap('', alias, ': ') + name + wrap('(', join(args, ', '), ')'), join(directives, ' '), selectionSet], ' ');
  695. },
  696. Argument: function Argument(_ref4) {
  697. var name = _ref4.name;
  698. var value = _ref4.value;
  699. return name + ': ' + value;
  700. },
  701. // Fragments
  702. FragmentSpread: function FragmentSpread(_ref5) {
  703. var name = _ref5.name;
  704. var directives = _ref5.directives;
  705. return '...' + name + wrap(' ', join(directives, ' '));
  706. },
  707. InlineFragment: function InlineFragment(_ref6) {
  708. var typeCondition = _ref6.typeCondition;
  709. var directives = _ref6.directives;
  710. var selectionSet = _ref6.selectionSet;
  711. return join(['...', wrap('on ', typeCondition), join(directives, ' '), selectionSet], ' ');
  712. },
  713. FragmentDefinition: function FragmentDefinition(_ref7) {
  714. var name = _ref7.name;
  715. var typeCondition = _ref7.typeCondition;
  716. var directives = _ref7.directives;
  717. var selectionSet = _ref7.selectionSet;
  718. return 'fragment ' + name + ' on ' + typeCondition + ' ' + wrap('', join(directives, ' '), ' ') + selectionSet;
  719. },
  720. // Value
  721. IntValue: function IntValue(_ref8) {
  722. var value = _ref8.value;
  723. return value;
  724. },
  725. FloatValue: function FloatValue(_ref9) {
  726. var value = _ref9.value;
  727. return value;
  728. },
  729. StringValue: function StringValue(_ref10) {
  730. var value = _ref10.value;
  731. return JSON.stringify(value);
  732. },
  733. BooleanValue: function BooleanValue(_ref11) {
  734. var value = _ref11.value;
  735. return JSON.stringify(value);
  736. },
  737. EnumValue: function EnumValue(_ref12) {
  738. var value = _ref12.value;
  739. return value;
  740. },
  741. ListValue: function ListValue(_ref13) {
  742. var values = _ref13.values;
  743. return '[' + join(values, ', ') + ']';
  744. },
  745. ObjectValue: function ObjectValue(_ref14) {
  746. var fields = _ref14.fields;
  747. return '{' + join(fields, ', ') + '}';
  748. },
  749. ObjectField: function ObjectField(_ref15) {
  750. var name = _ref15.name;
  751. var value = _ref15.value;
  752. return name + ': ' + value;
  753. },
  754. // Directive
  755. Directive: function Directive(_ref16) {
  756. var name = _ref16.name;
  757. var args = _ref16.arguments;
  758. return '@' + name + wrap('(', join(args, ', '), ')');
  759. },
  760. // Type
  761. NamedType: function NamedType(_ref17) {
  762. var name = _ref17.name;
  763. return name;
  764. },
  765. ListType: function ListType(_ref18) {
  766. var type = _ref18.type;
  767. return '[' + type + ']';
  768. },
  769. NonNullType: function NonNullType(_ref19) {
  770. var type = _ref19.type;
  771. return type + '!';
  772. },
  773. // Type System Definitions
  774. SchemaDefinition: function SchemaDefinition(_ref20) {
  775. var directives = _ref20.directives;
  776. var operationTypes = _ref20.operationTypes;
  777. return join(['schema', join(directives, ' '), block(operationTypes)], ' ');
  778. },
  779. OperationTypeDefinition: function OperationTypeDefinition(_ref21) {
  780. var operation = _ref21.operation;
  781. var type = _ref21.type;
  782. return operation + ': ' + type;
  783. },
  784. ScalarTypeDefinition: function ScalarTypeDefinition(_ref22) {
  785. var name = _ref22.name;
  786. var directives = _ref22.directives;
  787. return join(['scalar', name, join(directives, ' ')], ' ');
  788. },
  789. ObjectTypeDefinition: function ObjectTypeDefinition(_ref23) {
  790. var name = _ref23.name;
  791. var interfaces = _ref23.interfaces;
  792. var directives = _ref23.directives;
  793. var fields = _ref23.fields;
  794. return join(['type', name, wrap('implements ', join(interfaces, ', ')), join(directives, ' '), block(fields)], ' ');
  795. },
  796. FieldDefinition: function FieldDefinition(_ref24) {
  797. var name = _ref24.name;
  798. var args = _ref24.arguments;
  799. var type = _ref24.type;
  800. var directives = _ref24.directives;
  801. return name + wrap('(', join(args, ', '), ')') + ': ' + type + wrap(' ', join(directives, ' '));
  802. },
  803. InputValueDefinition: function InputValueDefinition(_ref25) {
  804. var name = _ref25.name;
  805. var type = _ref25.type;
  806. var defaultValue = _ref25.defaultValue;
  807. var directives = _ref25.directives;
  808. return join([name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')], ' ');
  809. },
  810. InterfaceTypeDefinition: function InterfaceTypeDefinition(_ref26) {
  811. var name = _ref26.name;
  812. var directives = _ref26.directives;
  813. var fields = _ref26.fields;
  814. return join(['interface', name, join(directives, ' '), block(fields)], ' ');
  815. },
  816. UnionTypeDefinition: function UnionTypeDefinition(_ref27) {
  817. var name = _ref27.name;
  818. var directives = _ref27.directives;
  819. var types = _ref27.types;
  820. return join(['union', name, join(directives, ' '), '= ' + join(types, ' | ')], ' ');
  821. },
  822. EnumTypeDefinition: function EnumTypeDefinition(_ref28) {
  823. var name = _ref28.name;
  824. var directives = _ref28.directives;
  825. var values = _ref28.values;
  826. return join(['enum', name, join(directives, ' '), block(values)], ' ');
  827. },
  828. EnumValueDefinition: function EnumValueDefinition(_ref29) {
  829. var name = _ref29.name;
  830. var directives = _ref29.directives;
  831. return join([name, join(directives, ' ')], ' ');
  832. },
  833. InputObjectTypeDefinition: function InputObjectTypeDefinition(_ref30) {
  834. var name = _ref30.name;
  835. var directives = _ref30.directives;
  836. var fields = _ref30.fields;
  837. return join(['input', name, join(directives, ' '), block(fields)], ' ');
  838. },
  839. TypeExtensionDefinition: function TypeExtensionDefinition(_ref31) {
  840. var definition = _ref31.definition;
  841. return 'extend ' + definition;
  842. },
  843. DirectiveDefinition: function DirectiveDefinition(_ref32) {
  844. var name = _ref32.name;
  845. var args = _ref32.arguments;
  846. var locations = _ref32.locations;
  847. return 'directive @' + name + wrap('(', join(args, ', '), ')') + ' on ' + join(locations, ' | ');
  848. }
  849. };
  850. /**
  851. * Given maybeArray, print an empty string if it is null or empty, otherwise
  852. * print all items together separated by separator if provided
  853. */
  854. function join(maybeArray, separator) {
  855. return maybeArray ? maybeArray.filter(function (x) {
  856. return x;
  857. }).join(separator || '') : '';
  858. }
  859. /**
  860. * Given array, print each item on its own line, wrapped in an
  861. * indented "{ }" block.
  862. */
  863. function block(array) {
  864. return array && array.length !== 0 ? indent('{\n' + join(array, '\n')) + '\n}' : '{}';
  865. }
  866. /**
  867. * If maybeString is not null or empty, then wrap with start and end, otherwise
  868. * print an empty string.
  869. */
  870. function wrap(start, maybeString, end) {
  871. return maybeString ? start + maybeString + (end || '') : '';
  872. }
  873. function indent(maybeString) {
  874. return maybeString && maybeString.replace(/\n/g, '\n ');
  875. }
  876. /***/ },
  877. /* 2 */
  878. /***/ function(module, exports) {
  879. 'use strict';
  880. Object.defineProperty(exports, "__esModule", {
  881. value: true
  882. });
  883. exports.visit = visit;
  884. exports.visitInParallel = visitInParallel;
  885. exports.visitWithTypeInfo = visitWithTypeInfo;
  886. /**
  887. * Copyright (c) 2015, Facebook, Inc.
  888. * All rights reserved.
  889. *
  890. * This source code is licensed under the BSD-style license found in the
  891. * LICENSE file in the root directory of this source tree. An additional grant
  892. * of patent rights can be found in the PATENTS file in the same directory.
  893. */
  894. var QueryDocumentKeys = exports.QueryDocumentKeys = {
  895. Name: [],
  896. Document: ['definitions'],
  897. OperationDefinition: ['name', 'variableDefinitions', 'directives', 'selectionSet'],
  898. VariableDefinition: ['variable', 'type', 'defaultValue'],
  899. Variable: ['name'],
  900. SelectionSet: ['selections'],
  901. Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
  902. Argument: ['name', 'value'],
  903. FragmentSpread: ['name', 'directives'],
  904. InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
  905. FragmentDefinition: ['name', 'typeCondition', 'directives', 'selectionSet'],
  906. IntValue: [],
  907. FloatValue: [],
  908. StringValue: [],
  909. BooleanValue: [],
  910. EnumValue: [],
  911. ListValue: ['values'],
  912. ObjectValue: ['fields'],
  913. ObjectField: ['name', 'value'],
  914. Directive: ['name', 'arguments'],
  915. NamedType: ['name'],
  916. ListType: ['type'],
  917. NonNullType: ['type'],
  918. SchemaDefinition: ['directives', 'operationTypes'],
  919. OperationTypeDefinition: ['type'],
  920. ScalarTypeDefinition: ['name', 'directives'],
  921. ObjectTypeDefinition: ['name', 'interfaces', 'directives', 'fields'],
  922. FieldDefinition: ['name', 'arguments', 'type', 'directives'],
  923. InputValueDefinition: ['name', 'type', 'defaultValue', 'directives'],
  924. InterfaceTypeDefinition: ['name', 'directives', 'fields'],
  925. UnionTypeDefinition: ['name', 'directives', 'types'],
  926. EnumTypeDefinition: ['name', 'directives', 'values'],
  927. EnumValueDefinition: ['name', 'directives'],
  928. InputObjectTypeDefinition: ['name', 'directives', 'fields'],
  929. TypeExtensionDefinition: ['definition'],
  930. DirectiveDefinition: ['name', 'arguments', 'locations']
  931. };
  932. var BREAK = exports.BREAK = {};
  933. /**
  934. * visit() will walk through an AST using a depth first traversal, calling
  935. * the visitor's enter function at each node in the traversal, and calling the
  936. * leave function after visiting that node and all of its child nodes.
  937. *
  938. * By returning different values from the enter and leave functions, the
  939. * behavior of the visitor can be altered, including skipping over a sub-tree of
  940. * the AST (by returning false), editing the AST by returning a value or null
  941. * to remove the value, or to stop the whole traversal by returning BREAK.
  942. *
  943. * When using visit() to edit an AST, the original AST will not be modified, and
  944. * a new version of the AST with the changes applied will be returned from the
  945. * visit function.
  946. *
  947. * const editedAST = visit(ast, {
  948. * enter(node, key, parent, path, ancestors) {
  949. * // @return
  950. * // undefined: no action
  951. * // false: skip visiting this node
  952. * // visitor.BREAK: stop visiting altogether
  953. * // null: delete this node
  954. * // any value: replace this node with the returned value
  955. * },
  956. * leave(node, key, parent, path, ancestors) {
  957. * // @return
  958. * // undefined: no action
  959. * // false: no action
  960. * // visitor.BREAK: stop visiting altogether
  961. * // null: delete this node
  962. * // any value: replace this node with the returned value
  963. * }
  964. * });
  965. *
  966. * Alternatively to providing enter() and leave() functions, a visitor can
  967. * instead provide functions named the same as the kinds of AST nodes, or
  968. * enter/leave visitors at a named key, leading to four permutations of
  969. * visitor API:
  970. *
  971. * 1) Named visitors triggered when entering a node a specific kind.
  972. *
  973. * visit(ast, {
  974. * Kind(node) {
  975. * // enter the "Kind" node
  976. * }
  977. * })
  978. *
  979. * 2) Named visitors that trigger upon entering and leaving a node of
  980. * a specific kind.
  981. *
  982. * visit(ast, {
  983. * Kind: {
  984. * enter(node) {
  985. * // enter the "Kind" node
  986. * }
  987. * leave(node) {
  988. * // leave the "Kind" node
  989. * }
  990. * }
  991. * })
  992. *
  993. * 3) Generic visitors that trigger upon entering and leaving any node.
  994. *
  995. * visit(ast, {
  996. * enter(node) {
  997. * // enter any node
  998. * },
  999. * leave(node) {
  1000. * // leave any node
  1001. * }
  1002. * })
  1003. *
  1004. * 4) Parallel visitors for entering and leaving nodes of a specific kind.
  1005. *
  1006. * visit(ast, {
  1007. * enter: {
  1008. * Kind(node) {
  1009. * // enter the "Kind" node
  1010. * }
  1011. * },
  1012. * leave: {
  1013. * Kind(node) {
  1014. * // leave the "Kind" node
  1015. * }
  1016. * }
  1017. * })
  1018. */
  1019. function visit(root, visitor, keyMap) {
  1020. var visitorKeys = keyMap || QueryDocumentKeys;
  1021. var stack = void 0;
  1022. var inArray = Array.isArray(root);
  1023. var keys = [root];
  1024. var index = -1;
  1025. var edits = [];
  1026. var parent = void 0;
  1027. var path = [];
  1028. var ancestors = [];
  1029. var newRoot = root;
  1030. do {
  1031. index++;
  1032. var isLeaving = index === keys.length;
  1033. var key = void 0;
  1034. var node = void 0;
  1035. var isEdited = isLeaving && edits.length !== 0;
  1036. if (isLeaving) {
  1037. key = ancestors.length === 0 ? undefined : path.pop();
  1038. node = parent;
  1039. parent = ancestors.pop();
  1040. if (isEdited) {
  1041. if (inArray) {
  1042. node = node.slice();
  1043. } else {
  1044. var clone = {};
  1045. for (var k in node) {
  1046. if (node.hasOwnProperty(k)) {
  1047. clone[k] = node[k];
  1048. }
  1049. }
  1050. node = clone;
  1051. }
  1052. var editOffset = 0;
  1053. for (var ii = 0; ii < edits.length; ii++) {
  1054. var editKey = edits[ii][0];
  1055. var editValue = edits[ii][1];
  1056. if (inArray) {
  1057. editKey -= editOffset;
  1058. }
  1059. if (inArray && editValue === null) {
  1060. node.splice(editKey, 1);
  1061. editOffset++;
  1062. } else {
  1063. node[editKey] = editValue;
  1064. }
  1065. }
  1066. }
  1067. index = stack.index;
  1068. keys = stack.keys;
  1069. edits = stack.edits;
  1070. inArray = stack.inArray;
  1071. stack = stack.prev;
  1072. } else {
  1073. key = parent ? inArray ? index : keys[index] : undefined;
  1074. node = parent ? parent[key] : newRoot;
  1075. if (node === null || node === undefined) {
  1076. continue;
  1077. }
  1078. if (parent) {
  1079. path.push(key);
  1080. }
  1081. }
  1082. var result = void 0;
  1083. if (!Array.isArray(node)) {
  1084. if (!isNode(node)) {
  1085. throw new Error('Invalid AST Node: ' + JSON.stringify(node));
  1086. }
  1087. var visitFn = getVisitFn(visitor, node.kind, isLeaving);
  1088. if (visitFn) {
  1089. result = visitFn.call(visitor, node, key, parent, path, ancestors);
  1090. if (result === BREAK) {
  1091. break;
  1092. }
  1093. if (result === false) {
  1094. if (!isLeaving) {
  1095. path.pop();
  1096. continue;
  1097. }
  1098. } else if (result !== undefined) {
  1099. edits.push([key, result]);
  1100. if (!isLeaving) {
  1101. if (isNode(result)) {
  1102. node = result;
  1103. } else {
  1104. path.pop();
  1105. continue;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. if (result === undefined && isEdited) {
  1112. edits.push([key, node]);
  1113. }
  1114. if (!isLeaving) {
  1115. stack = { inArray: inArray, index: index, keys: keys, edits: edits, prev: stack };
  1116. inArray = Array.isArray(node);
  1117. keys = inArray ? node : visitorKeys[node.kind] || [];
  1118. index = -1;
  1119. edits = [];
  1120. if (parent) {
  1121. ancestors.push(parent);
  1122. }
  1123. parent = node;
  1124. }
  1125. } while (stack !== undefined);
  1126. if (edits.length !== 0) {
  1127. newRoot = edits[edits.length - 1][1];
  1128. }
  1129. return newRoot;
  1130. }
  1131. function isNode(maybeNode) {
  1132. return maybeNode && typeof maybeNode.kind === 'string';
  1133. }
  1134. /**
  1135. * Creates a new visitor instance which delegates to many visitors to run in
  1136. * parallel. Each visitor will be visited for each node before moving on.
  1137. *
  1138. * If a prior visitor edits a node, no following visitors will see that node.
  1139. */
  1140. function visitInParallel(visitors) {
  1141. var skipping = new Array(visitors.length);
  1142. return {
  1143. enter: function enter(node) {
  1144. for (var i = 0; i < visitors.length; i++) {
  1145. if (!skipping[i]) {
  1146. var fn = getVisitFn(visitors[i], node.kind, /* isLeaving */false);
  1147. if (fn) {
  1148. var result = fn.apply(visitors[i], arguments);
  1149. if (result === false) {
  1150. skipping[i] = node;
  1151. } else if (result === BREAK) {
  1152. skipping[i] = BREAK;
  1153. } else if (result !== undefined) {
  1154. return result;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. },
  1160. leave: function leave(node) {
  1161. for (var i = 0; i < visitors.length; i++) {
  1162. if (!skipping[i]) {
  1163. var fn = getVisitFn(visitors[i], node.kind, /* isLeaving */true);
  1164. if (fn) {
  1165. var result = fn.apply(visitors[i], arguments);
  1166. if (result === BREAK) {
  1167. skipping[i] = BREAK;
  1168. } else if (result !== undefined && result !== false) {
  1169. return result;
  1170. }
  1171. }
  1172. } else if (skipping[i] === node) {
  1173. skipping[i] = null;
  1174. }
  1175. }
  1176. }
  1177. };
  1178. }
  1179. /**
  1180. * Creates a new visitor instance which maintains a provided TypeInfo instance
  1181. * along with visiting visitor.
  1182. */
  1183. function visitWithTypeInfo(typeInfo, visitor) {
  1184. return {
  1185. enter: function enter(node) {
  1186. typeInfo.enter(node);
  1187. var fn = getVisitFn(visitor, node.kind, /* isLeaving */false);
  1188. if (fn) {
  1189. var result = fn.apply(visitor, arguments);
  1190. if (result !== undefined) {
  1191. typeInfo.leave(node);
  1192. if (isNode(result)) {
  1193. typeInfo.enter(result);
  1194. }
  1195. }
  1196. return result;
  1197. }
  1198. },
  1199. leave: function leave(node) {
  1200. var fn = getVisitFn(visitor, node.kind, /* isLeaving */true);
  1201. var result = void 0;
  1202. if (fn) {
  1203. result = fn.apply(visitor, arguments);
  1204. }
  1205. typeInfo.leave(node);
  1206. return result;
  1207. }
  1208. };
  1209. }
  1210. /**
  1211. * Given a visitor instance, if it is leaving or not, and a node kind, return
  1212. * the function the visitor runtime should call.
  1213. */
  1214. function getVisitFn(visitor, kind, isLeaving) {
  1215. var kindVisitor = visitor[kind];
  1216. if (kindVisitor) {
  1217. if (!isLeaving && typeof kindVisitor === 'function') {
  1218. // { Kind() {} }
  1219. return kindVisitor;
  1220. }
  1221. var kindSpecificVisitor = isLeaving ? kindVisitor.leave : kindVisitor.enter;
  1222. if (typeof kindSpecificVisitor === 'function') {
  1223. // { Kind: { enter() {}, leave() {} } }
  1224. return kindSpecificVisitor;
  1225. }
  1226. } else {
  1227. var specificVisitor = isLeaving ? visitor.leave : visitor.enter;
  1228. if (specificVisitor) {
  1229. if (typeof specificVisitor === 'function') {
  1230. // { enter() {}, leave() {} }
  1231. return specificVisitor;
  1232. }
  1233. var specificKindVisitor = specificVisitor[kind];
  1234. if (typeof specificKindVisitor === 'function') {
  1235. // { enter: { Kind() {} }, leave: { Kind() {} } }
  1236. return specificKindVisitor;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. /***/ }
  1242. /******/ ]);
  1243. /***/ }),
  1244. /* 9 */
  1245. /***/ (function(module, exports, __webpack_require__) {
  1246. "use strict";
  1247. /* WEBPACK VAR INJECTION */(function(global) {
  1248. function __export(m) {
  1249. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  1250. }
  1251. var Backoff = __webpack_require__(3);
  1252. var eventemitter3_1 = __webpack_require__(4);
  1253. var _global = typeof global !== 'undefined' ? global : (typeof window !== 'undefined' ? window : {});
  1254. var NativeWebSocket = _global.WebSocket || _global.MozWebSocket;
  1255. var messageTypes_1 = __webpack_require__(1);
  1256. var protocols_1 = __webpack_require__(2);
  1257. var isString = __webpack_require__(6);
  1258. var isObject = __webpack_require__(5);
  1259. __export(__webpack_require__(0));
  1260. var DEFAULT_SUBSCRIPTION_TIMEOUT = 5000;
  1261. var SubscriptionClient = (function () {
  1262. function SubscriptionClient(url, options, webSocketImpl) {
  1263. var _a = (options || {}), _b = _a.connectionCallback, connectionCallback = _b === void 0 ? undefined : _b, _c = _a.connectionParams, connectionParams = _c === void 0 ? {} : _c, _d = _a.timeout, timeout = _d === void 0 ? DEFAULT_SUBSCRIPTION_TIMEOUT : _d, _e = _a.reconnect, reconnect = _e === void 0 ? false : _e, _f = _a.reconnectionAttempts, reconnectionAttempts = _f === void 0 ? Infinity : _f;
  1264. this.wsImpl = webSocketImpl || NativeWebSocket;
  1265. if (!this.wsImpl) {
  1266. throw new Error('Unable to find native implementation, or alternative implementation for WebSocket!');
  1267. }
  1268. this.connectionParams = connectionParams;
  1269. this.connectionCallback = connectionCallback;
  1270. this.url = url;
  1271. this.subscriptions = {};
  1272. this.maxId = 0;
  1273. this.subscriptionTimeout = timeout;
  1274. this.waitingSubscriptions = {};
  1275. this.unsentMessagesQueue = [];
  1276. this.reconnect = reconnect;
  1277. this.reconnectSubscriptions = {};
  1278. this.reconnecting = false;
  1279. this.reconnectionAttempts = reconnectionAttempts;
  1280. this.backoff = new Backoff({ jitter: 0.5 });
  1281. this.eventEmitter = new eventemitter3_1.EventEmitter();
  1282. this.connect();
  1283. }
  1284. Object.defineProperty(SubscriptionClient.prototype, "status", {
  1285. get: function () {
  1286. return this.client.readyState;
  1287. },
  1288. enumerable: true,
  1289. configurable: true
  1290. });
  1291. SubscriptionClient.prototype.close = function () {
  1292. this.client.close();
  1293. };
  1294. SubscriptionClient.prototype.subscribe = function (options, handler) {
  1295. var _this = this;
  1296. var query = options.query, variables = options.variables, operationName = options.operationName, context = options.context;
  1297. if (!query) {
  1298. throw new Error('Must provide `query` to subscribe.');
  1299. }
  1300. if (!handler) {
  1301. throw new Error('Must provide `handler` to subscribe.');
  1302. }
  1303. if (!isString(query) ||
  1304. (operationName && !isString(operationName)) ||
  1305. (variables && !isObject(variables))) {
  1306. throw new Error('Incorrect option types to subscribe. `subscription` must be a string,' +
  1307. '`operationName` must be a string, and `variables` must be an object.');
  1308. }
  1309. var subId = this.generateSubscriptionId();
  1310. var message = Object.assign(options, { type: messageTypes_1.SUBSCRIPTION_START, id: subId });
  1311. this.sendMessage(message);
  1312. this.subscriptions[subId] = { options: options, handler: handler };
  1313. this.waitingSubscriptions[subId] = true;
  1314. setTimeout(function () {
  1315. if (_this.waitingSubscriptions[subId]) {
  1316. handler([new Error('Subscription timed out - no response from server')]);
  1317. _this.unsubscribe(subId);
  1318. }
  1319. }, this.subscriptionTimeout);
  1320. return subId;
  1321. };
  1322. SubscriptionClient.prototype.on = function (eventName, callback, context) {
  1323. var handler = this.eventEmitter.on(eventName, callback, context);
  1324. return function () {
  1325. handler.off(eventName, callback, context);
  1326. };
  1327. };
  1328. SubscriptionClient.prototype.onConnect = function (callback, context) {
  1329. return this.on('connect', callback, context);
  1330. };
  1331. SubscriptionClient.prototype.onDisconnect = function (callback, context) {
  1332. return this.on('disconnect', callback, context);
  1333. };
  1334. SubscriptionClient.prototype.onReconnect = function (callback, context) {
  1335. return this.on('reconnect', callback, context);
  1336. };
  1337. SubscriptionClient.prototype.unsubscribe = function (id) {
  1338. delete this.subscriptions[id];
  1339. delete this.waitingSubscriptions[id];
  1340. var message = { id: id, type: messageTypes_1.SUBSCRIPTION_END };
  1341. this.sendMessage(message);
  1342. };
  1343. SubscriptionClient.prototype.unsubscribeAll = function () {
  1344. var _this = this;
  1345. Object.keys(this.subscriptions).forEach(function (subId) {
  1346. _this.unsubscribe(parseInt(subId));
  1347. });
  1348. };
  1349. SubscriptionClient.prototype.sendMessage = function (message) {
  1350. switch (this.client.readyState) {
  1351. case this.client.OPEN:
  1352. this.client.send(JSON.stringify(message));
  1353. break;
  1354. case this.client.CONNECTING:
  1355. this.unsentMessagesQueue.push(message);
  1356. break;
  1357. case this.client.CLOSING:
  1358. case this.client.CLOSED:
  1359. default:
  1360. if (!this.reconnecting) {
  1361. throw new Error('Client is not connected to a websocket.');
  1362. }
  1363. }
  1364. };
  1365. SubscriptionClient.prototype.generateSubscriptionId = function () {
  1366. var id = this.maxId;
  1367. this.maxId += 1;
  1368. return id;
  1369. };
  1370. SubscriptionClient.prototype.formatErrors = function (errors) {
  1371. if (Array.isArray(errors)) {
  1372. return errors;
  1373. }
  1374. if (errors && errors.message) {
  1375. return [errors];
  1376. }
  1377. return [{ message: 'Unknown error' }];
  1378. };
  1379. SubscriptionClient.prototype.tryReconnect = function () {
  1380. var _this = this;
  1381. if (!this.reconnect) {
  1382. return;
  1383. }
  1384. if (this.backoff.attempts > this.reconnectionAttempts) {
  1385. return;
  1386. }
  1387. if (!this.reconnecting) {
  1388. this.reconnectSubscriptions = this.subscriptions;
  1389. this.subscriptions = {};
  1390. this.waitingSubscriptions = {};
  1391. this.reconnecting = true;
  1392. }
  1393. var delay = this.backoff.duration();
  1394. setTimeout(function () {
  1395. _this.connect(true);
  1396. }, delay);
  1397. };
  1398. SubscriptionClient.prototype.connect = function (isReconnect) {
  1399. var _this = this;
  1400. if (isReconnect === void 0) { isReconnect = false; }
  1401. this.client = new this.wsImpl(this.url, protocols_1.GRAPHQL_SUBSCRIPTIONS);
  1402. this.client.onopen = function () {
  1403. _this.eventEmitter.emit(isReconnect ? 'reconnect' : 'connect');
  1404. _this.reconnecting = false;
  1405. _this.backoff.reset();
  1406. _this.sendMessage({ type: messageTypes_1.INIT, payload: _this.connectionParams });
  1407. Object.keys(_this.reconnectSubscriptions).forEach(function (key) {
  1408. var _a = _this.reconnectSubscriptions[key], options = _a.options, handler = _a.handler;
  1409. _this.subscribe(options, handler);
  1410. });
  1411. _this.unsentMessagesQueue.forEach(function (message) {
  1412. _this.client.send(JSON.stringify(message));
  1413. });
  1414. _this.unsentMessagesQueue = [];
  1415. };
  1416. this.client.onclose = function () {
  1417. _this.eventEmitter.emit('disconnect');
  1418. _this.tryReconnect();
  1419. };
  1420. this.client.onerror = function () {
  1421. };
  1422. this.client.onmessage = function (_a) {
  1423. var data = _a.data;
  1424. var parsedMessage;
  1425. try {
  1426. parsedMessage = JSON.parse(data);
  1427. }
  1428. catch (e) {
  1429. throw new Error("Message must be JSON-parseable. Got: " + data);
  1430. }
  1431. var subId = parsedMessage.id;
  1432. if ([messageTypes_1.KEEPALIVE, messageTypes_1.INIT_SUCCESS, messageTypes_1.INIT_FAIL].indexOf(parsedMessage.type) === -1 && !_this.subscriptions[subId]) {
  1433. _this.unsubscribe(subId);
  1434. if (parsedMessage.type === messageTypes_1.KEEPALIVE) {
  1435. return;
  1436. }
  1437. }
  1438. switch (parsedMessage.type) {
  1439. case messageTypes_1.INIT_FAIL:
  1440. if (_this.connectionCallback) {
  1441. _this.connectionCallback(parsedMessage.payload.error);
  1442. }
  1443. break;
  1444. case messageTypes_1.INIT_SUCCESS:
  1445. if (_this.connectionCallback) {
  1446. _this.connectionCallback();
  1447. }
  1448. break;
  1449. case messageTypes_1.SUBSCRIPTION_SUCCESS:
  1450. delete _this.waitingSubscriptions[subId];
  1451. break;
  1452. case messageTypes_1.SUBSCRIPTION_FAIL:
  1453. _this.subscriptions[subId].handler(_this.formatErrors(parsedMessage.payload.errors), null);
  1454. delete _this.subscriptions[subId];
  1455. delete _this.waitingSubscriptions[subId];
  1456. break;
  1457. case messageTypes_1.SUBSCRIPTION_DATA:
  1458. var payloadData = parsedMessage.payload.data || null;
  1459. var payloadErrors = parsedMessage.payload.errors ? _this.formatErrors(parsedMessage.payload.errors) : null;
  1460. _this.subscriptions[subId].handler(payloadErrors, payloadData);
  1461. break;
  1462. case messageTypes_1.KEEPALIVE:
  1463. break;
  1464. default:
  1465. throw new Error('Invalid message type!');
  1466. }
  1467. };
  1468. };
  1469. return SubscriptionClient;
  1470. }());
  1471. exports.SubscriptionClient = SubscriptionClient;
  1472. //# sourceMappingURL=client.js.map
  1473. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7)))
  1474. /***/ })
  1475. /******/ ]);