react-blips
Version:
Official React bindings for Blips
56 lines (43 loc) • 2.34 kB
JavaScript
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; }
import { Component, Children } from 'react';
import { GraphQLDirective, DirectiveLocation } from 'graphql';
import PropTypes from 'prop-types';
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 GraphQLDirective({
name: 'api',
description: 'Sends this operation to a real GraphQL server for execution',
locations: [DirectiveLocation.QUERY, DirectiveLocation.MUTATION, DirectiveLocation.SUBSCRIPTION]
});
_this.client.schema._directives.push(apiDirective);
return _this;
}
Provider.prototype.render = function render() {
return Children.only(this.props.children);
};
return Provider;
}(Component);
Provider.propTypes = {
client: PropTypes.shape({
state: PropTypes.object.isRequired,
schema: PropTypes.object.isRequired,
query: PropTypes.func.isRequired,
mutate: PropTypes.func.isRequired,
subscribe: PropTypes.func.isRequired,
fetch: PropTypes.func.isRequired
}).isRequired,
children: PropTypes.element.isRequired
};
Provider.childContextTypes = {
client: PropTypes.object.isRequired
};
export default Provider;