react-blips
Version:
Official React bindings for Blips
66 lines (47 loc) • 2.65 kB
JavaScript
;
exports.__esModule = true;
var _react = require('react');
var _graphql = require('graphql');
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 Provider = function (_Component) {
_inherits(Provider, _Component);
Provider.prototype.getChildContext = function getChildContext() {
return { client: this.client };
};
function Provider(props, context) {
_classCallCheck(this, Provider);
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
_this.client = props.client;
var apiDirective = new _graphql.GraphQLDirective({
name: 'api',
description: 'Sends this operation to a real GraphQL server for execution',
locations: [_graphql.DirectiveLocation.QUERY, _graphql.DirectiveLocation.MUTATION, _graphql.DirectiveLocation.SUBSCRIPTION]
});
_this.client.schema._directives.push(apiDirective);
return _this;
}
Provider.prototype.render = function render() {
return _react.Children.only(this.props.children);
};
return Provider;
}(_react.Component);
Provider.propTypes = {
client: _propTypes2.default.shape({
state: _propTypes2.default.object.isRequired,
schema: _propTypes2.default.object.isRequired,
query: _propTypes2.default.func.isRequired,
mutate: _propTypes2.default.func.isRequired,
subscribe: _propTypes2.default.func.isRequired,
fetch: _propTypes2.default.func.isRequired
}).isRequired,
children: _propTypes2.default.element.isRequired
};
Provider.childContextTypes = {
client: _propTypes2.default.object.isRequired
};
exports.default = Provider;