graphql-infer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,95 +0,56 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.graphqlInfer = undefined; | ||
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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
import React, { Component } from 'react'; | ||
import { makeProxy } from './utils'; | ||
import gql from 'graphql-tag'; | ||
import { graphql } from 'react-apollo'; | ||
var _templateObject = _taggedTemplateLiteral(['', ''], ['', '']); | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _utils = require('./utils'); | ||
var _graphqlTag = require('graphql-tag'); | ||
var _graphqlTag2 = _interopRequireDefault(_graphqlTag); | ||
var _reactApollo = require('react-apollo'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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; } | ||
/* Hoc */ | ||
var graphqlInfer = exports.graphqlInfer = function graphqlInfer(config) { | ||
return function (WrappedComponent) { | ||
return function (_Component) { | ||
_inherits(_class, _Component); | ||
export const graphqlInfer = config => WrappedComponent => { | ||
return class extends Component { | ||
function _class(props) { | ||
var _this$state; | ||
constructor(props) { | ||
super(props); | ||
let query = {}; | ||
let queryProxy = makeProxy(query); | ||
_classCallCheck(this, _class); | ||
this.state = { | ||
[config.query]: queryProxy, | ||
query: null | ||
}; | ||
} | ||
var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this, props)); | ||
componentDidMount() { | ||
const queryObj = this.state[config.query]; | ||
const query = ` | ||
query ${config.query} { | ||
${config.query} { | ||
${Object.keys(queryObj)} | ||
} | ||
} | ||
`; | ||
this.setState({ query }); | ||
} | ||
var query = {}; | ||
var queryProxy = (0, _utils.makeProxy)(query); | ||
_this.state = (_this$state = {}, _defineProperty(_this$state, config.query, queryProxy), _defineProperty(_this$state, 'query', null), _this$state); | ||
return _this; | ||
} | ||
_createClass(_class, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var queryObj = this.state[config.query]; | ||
var query = '\n query ' + config.query + ' {\n ' + config.query + ' {\n ' + Object.keys(queryObj) + '\n }\n }\n '; | ||
this.setState({ query: query }); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _this2 = this; | ||
if (this.state.query) { | ||
var GraphQLComponent = (0, _reactApollo.graphql)((0, _graphqlTag2.default)(_templateObject, this.state.query), { | ||
props: function props(_ref) { | ||
var ownProps = _ref.ownProps, | ||
data = _ref.data; | ||
if (data && !data.loading) { | ||
var newProps = {}; | ||
for (var prop in _this2.state[config.query]) { | ||
newProps[prop] = data[config.query][prop]; | ||
} | ||
return _extends({}, ownProps, _defineProperty({}, config.query, newProps)); | ||
} | ||
return _extends({}, ownProps, _this2.state); | ||
render() { | ||
if (this.state.query) { | ||
const GraphQLComponent = graphql(gql`${this.state.query}`, { | ||
props: ({ ownProps, data }) => { | ||
if (data && !data.loading) { | ||
let newProps = {}; | ||
for (let prop in this.state[config.query]) { | ||
newProps[prop] = data[config.query][prop]; | ||
} | ||
})(WrappedComponent); | ||
return _react2.default.createElement(GraphQLComponent, null); | ||
return _extends({}, ownProps, { | ||
[config.query]: newProps | ||
}); | ||
} | ||
return _extends({}, ownProps, this.state); | ||
} | ||
return _react2.default.createElement(WrappedComponent, _extends({}, this.state, this.props)); | ||
} | ||
}]); | ||
return _class; | ||
}(_react.Component); | ||
})(WrappedComponent); | ||
return React.createElement(GraphQLComponent, null); | ||
} | ||
return React.createElement(WrappedComponent, _extends({}, this.state, this.props)); | ||
} | ||
}; | ||
}; |
@@ -1,16 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var makeProxy = exports.makeProxy = function makeProxy(obj) { | ||
return new Proxy(obj, { | ||
get: function get(target, name) { | ||
//If property does not exist on object | ||
if (!target[name]) { | ||
target[name] = name.toString(); | ||
} | ||
return target[name]; | ||
export const makeProxy = obj => new Proxy(obj, { | ||
get(target, name) { | ||
//If property does not exist on object | ||
if (!target[name]) { | ||
target[name] = name.toString(); | ||
} | ||
}); | ||
}; | ||
return target[name]; | ||
} | ||
}); |
{ | ||
"name": "graphql-infer", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Infer graphQL queries and avoid writing graphQL queries", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92262
57