parse-legacy-protocol.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.parseLegacyProtocolMessage = void 0;
  15. var message_types_1 = require("../message-types");
  16. exports.parseLegacyProtocolMessage = function (connectionContext, message) {
  17. var messageToReturn = message;
  18. switch (message.type) {
  19. case message_types_1.default.INIT:
  20. connectionContext.isLegacy = true;
  21. messageToReturn = __assign(__assign({}, message), { type: message_types_1.default.GQL_CONNECTION_INIT });
  22. break;
  23. case message_types_1.default.SUBSCRIPTION_START:
  24. messageToReturn = {
  25. id: message.id,
  26. type: message_types_1.default.GQL_START,
  27. payload: {
  28. query: message.query,
  29. operationName: message.operationName,
  30. variables: message.variables,
  31. },
  32. };
  33. break;
  34. case message_types_1.default.SUBSCRIPTION_END:
  35. messageToReturn = __assign(__assign({}, message), { type: message_types_1.default.GQL_STOP });
  36. break;
  37. case message_types_1.default.GQL_CONNECTION_ACK:
  38. if (connectionContext.isLegacy) {
  39. messageToReturn = __assign(__assign({}, message), { type: message_types_1.default.INIT_SUCCESS });
  40. }
  41. break;
  42. case message_types_1.default.GQL_CONNECTION_ERROR:
  43. if (connectionContext.isLegacy) {
  44. messageToReturn = __assign(__assign({}, message), { type: message_types_1.default.INIT_FAIL, payload: message.payload.message ? { error: message.payload.message } : message.payload });
  45. }
  46. break;
  47. case message_types_1.default.GQL_ERROR:
  48. if (connectionContext.isLegacy) {
  49. messageToReturn = __assign(__assign({}, message), { type: message_types_1.default.SUBSCRIPTION_FAIL });
  50. }
  51. break;
  52. case message_types_1.default.GQL_DATA:
  53. if (connectionContext.isLegacy) {
  54. messageToReturn = __assign(__assign({}, message), { type: message_types_1.default.SUBSCRIPTION_DATA });
  55. }
  56. break;
  57. case message_types_1.default.GQL_COMPLETE:
  58. if (connectionContext.isLegacy) {
  59. messageToReturn = null;
  60. }
  61. break;
  62. case message_types_1.default.SUBSCRIPTION_SUCCESS:
  63. if (!connectionContext.isLegacy) {
  64. messageToReturn = null;
  65. }
  66. break;
  67. default:
  68. break;
  69. }
  70. return messageToReturn;
  71. };
  72. //# sourceMappingURL=parse-legacy-protocol.js.map