UNPKG

@rnga/orders

Version:

## Get schema from @prisma-cms 1. yarn get-api-schema -e http://localhost:4000 2. yarn build-api-fragments

222 lines (161 loc) 8.28 kB
'use strict'; exports.__esModule = true; exports.default = undefined; var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _class, _temp2; var _templateObject = _taggedTemplateLiteralLoose(['\n subscription user{\n user{\n mutation\n node{\n id\n }\n }\n }\n '], ['\n subscription user{\n user{\n mutation\n node{\n id\n }\n }\n }\n ']); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _graphqlTag = require('graphql-tag'); var _graphqlTag2 = _interopRequireDefault(_graphqlTag); var _context5 = require('@prisma-cms/context'); var _context6 = _interopRequireDefault(_context5); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var SubscriptionProvider = (_temp2 = _class = function (_Component) { _inherits(SubscriptionProvider, _Component); function SubscriptionProvider() { var _temp, _this, _ret; _classCallCheck(this, SubscriptionProvider); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { subscriptions: [] }, _temp), _possibleConstructorReturn(_this, _ret); } SubscriptionProvider.prototype.componentDidMount = function componentDidMount() { this.subscribe(); }; SubscriptionProvider.prototype.componentWillUnmount = function componentWillUnmount() { this.unsubscribe(); }; SubscriptionProvider.prototype.subscribe = function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { var _this2 = this; var client, subscriptions, subscribeUser, userSub; return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: client = this.context.client; if (client) { _context2.next = 4; break; } console.error("client is empty"); return _context2.abrupt('return'); case 4: _context2.next = 6; return this.unsubscribe(); case 6: subscriptions = this.state.subscriptions; subscribeUser = (0, _graphqlTag2.default)(_templateObject); _context2.next = 10; return client.subscribe({ query: subscribeUser, variables: {} }).subscribe({ next: function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(data) { return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return _this2.reloadData(); case 2: case 'end': return _context.stop(); } } }, _callee, _this2); })); return function next(_x) { return _ref2.apply(this, arguments); }; }(), error: function error(_error) { console.error('subscribeCalls callback with error: ', _error); } }); case 10: userSub = _context2.sent; subscriptions.push(userSub); this.setState({ subscriptions: subscriptions }); case 13: case 'end': return _context2.stop(); } } }, _callee2, this); })); function subscribe() { return _ref.apply(this, arguments); } return subscribe; }(); SubscriptionProvider.prototype.unsubscribe = function unsubscribe() { var _this3 = this; return new Promise(function (resolve) { var subscriptions = _this3.state.subscriptions; if (subscriptions && subscriptions.length) { subscriptions.map(function (n) { n.unsubscribe(); }); Object.assign(_this3.state, { subscriptions: [] }); } resolve(); }); }; SubscriptionProvider.prototype.reloadData = function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee3() { var _context3, client, loadApiData; return _regenerator2.default.wrap(function _callee3$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context3 = this.context, client = _context3.client, loadApiData = _context3.loadApiData; _context4.next = 3; return loadApiData(); case 3: _context4.next = 5; return client.reFetchObservableQueries(); case 5: case 'end': return _context4.stop(); } } }, _callee3, this); })); function reloadData() { return _ref3.apply(this, arguments); } return reloadData; }(); SubscriptionProvider.prototype.render = function render() { var _props = this.props, children = _props.children, user = _props.user, client = _props.client, loadApiData = _props.loadApiData, other = _objectWithoutProperties(_props, ['children', 'user', 'client', 'loadApiData']); return children ? _react2.default.createElement(children.type, _extends({}, children.props, other)) : null; }; return SubscriptionProvider; }(_react.Component), _class.contextType = _context6.default, _temp2); exports.default = SubscriptionProvider; module.exports = exports['default'];