graphql-react
Advanced tools
Comparing version 1.0.0 to 1.0.1
# graphql-react changelog | ||
## 1.0.1 | ||
* Updated dependencies. | ||
* Fixed accidental distribution code Prettier ignoring. | ||
* Replaced `ava` with `node-tap` for testing. Tests don't require a special CLI, no longer transpile on the fly, are faster and AVA no longer dictates the Babel version. | ||
* Tests run against the actual dist `.mjs` and `.js` files in native ESM (`--experimental-modules`) and CJS environments. | ||
* Updated Babel config: | ||
* Use `babel.config.js` instead of `.babelrc.js`. | ||
* Renamed the `ESM` environment variable to `BABEL_ESM` to be more specific. | ||
* Improved `package.json` scripts: | ||
* Leveraged `npm-run-all` more for parallelism and reduced noise. | ||
* Removed linting fix scripts. | ||
* Linting included in the `test` script. Travis CI will fail PR's with lint errors. | ||
* Custom watch script. | ||
* No longer use `cross-env`; contributors with Windows may setup and use a Bash shell. | ||
* Improved ESLint config: | ||
* Use the right `sourceType` for `.js` (`script`) and `.mjs` (`module`) files. | ||
* Removed redundant `eslint-plugin-ava` dev dependency and config. | ||
* Use `eslint-plugin-import` and `eslint-plugin-node` and enable more rules. | ||
* Undo overriding ESLint ignoring dotfiles by default as there are none now. | ||
* Moved the example project to [a separate repo](https://github.com/jaydenseric/graphql-react-examples). | ||
* Better readme logo alt text. | ||
## 1.0.0 | ||
@@ -4,0 +27,0 @@ |
@@ -1,125 +0,161 @@ | ||
"use strict"; | ||
'use strict' | ||
exports.__esModule = true; | ||
exports.Query = exports.Consumer = exports.Provider = void 0; | ||
exports.__esModule = true | ||
exports.Query = exports.Consumer = exports.Provider = void 0 | ||
var _objectAssign = _interopRequireDefault(require("object-assign")); | ||
var _objectAssign = _interopRequireDefault(require('object-assign')) | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react = _interopRequireDefault(require('react')) | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _propTypes = _interopRequireDefault(require('prop-types')) | ||
var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal")); | ||
var _fastDeepEqual = _interopRequireDefault(require('fast-deep-equal')) | ||
var _graphql = require("./graphql"); | ||
var _graphql = require('./graphql') | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { default: obj } | ||
} | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype.__proto__ = superClass && superClass.prototype | ||
subClass.__proto__ = superClass | ||
} | ||
var _React$createContext = _react.default.createContext(), | ||
Provider = _React$createContext.Provider, | ||
Consumer = _React$createContext.Consumer; | ||
Provider = _React$createContext.Provider, | ||
Consumer = _React$createContext.Consumer | ||
exports.Consumer = Consumer; | ||
exports.Provider = Provider; | ||
exports.Consumer = Consumer | ||
exports.Provider = Provider | ||
var GraphQLQuery = function (_React$Component) { | ||
_inheritsLoose(GraphQLQuery, _React$Component); | ||
var GraphQLQuery = (function(_React$Component) { | ||
function GraphQLQuery(props) { | ||
var _this; | ||
var _this | ||
_this = _React$Component.call(this, props) || this; | ||
_this = _React$Component.call(this, props) || this | ||
_this.handleCacheUpdate = function (requestCache) { | ||
if (!requestCache && _this.props.loadOnReset) _this.load();else _this.setState({ | ||
requestCache: requestCache | ||
}); | ||
}; | ||
_this.handleCacheUpdate = function(requestCache) { | ||
if (!requestCache && _this.props.loadOnReset) _this.load() | ||
else | ||
_this.setState({ | ||
requestCache: requestCache | ||
}) | ||
} | ||
_this.operation = function () { | ||
_this.operation = function() { | ||
return { | ||
variables: _this.props.variables, | ||
query: _this.props.query | ||
}; | ||
}; | ||
} | ||
} | ||
_this.load = function () { | ||
_this.load = function() { | ||
var stateUpdate = { | ||
loading: true | ||
}; | ||
} | ||
var _this$props$graphql$q = _this.props.graphql.query({ | ||
operation: _this.operation(), | ||
fetchOptionsOverride: _this.props.fetchOptionsOverride, | ||
resetOnLoad: _this.props.resetOnLoad | ||
}), | ||
fetchOptionsHash = _this$props$graphql$q.fetchOptionsHash, | ||
cache = _this$props$graphql$q.cache, | ||
request = _this$props$graphql$q.request; | ||
operation: _this.operation(), | ||
fetchOptionsOverride: _this.props.fetchOptionsOverride, | ||
resetOnLoad: _this.props.resetOnLoad | ||
}), | ||
fetchOptionsHash = _this$props$graphql$q.fetchOptionsHash, | ||
cache = _this$props$graphql$q.cache, | ||
request = _this$props$graphql$q.request | ||
if (fetchOptionsHash !== _this.state.fetchOptionsHash) { | ||
stateUpdate.fetchOptionsHash = fetchOptionsHash; | ||
stateUpdate.fetchOptionsHash = fetchOptionsHash | ||
_this.props.graphql.offCacheUpdate(_this.state.fetchOptionsHash, _this.handleCacheUpdate); | ||
_this.props.graphql.offCacheUpdate( | ||
_this.state.fetchOptionsHash, | ||
_this.handleCacheUpdate | ||
) | ||
_this.props.graphql.onCacheUpdate(fetchOptionsHash, _this.handleCacheUpdate); | ||
_this.props.graphql.onCacheUpdate( | ||
fetchOptionsHash, | ||
_this.handleCacheUpdate | ||
) | ||
} | ||
if (cache) stateUpdate.requestCache = cache; | ||
if (cache) stateUpdate.requestCache = cache | ||
_this.setState(stateUpdate, function () { | ||
return request.then(function () { | ||
_this.setState(stateUpdate, function() { | ||
return request.then(function() { | ||
return _this.setState({ | ||
loading: false | ||
}); | ||
}); | ||
}); | ||
}) | ||
}) | ||
}) | ||
return request; | ||
}; | ||
return request | ||
} | ||
_this.state = { | ||
loading: props.loadOnMount | ||
}; | ||
} | ||
if (props.loadOnMount) { | ||
var fetchOptions = props.graphql.constructor.fetchOptions(_this.operation()); | ||
if (props.fetchOptionsOverride) props.fetchOptionsOverride(fetchOptions); | ||
_this.state.fetchOptionsHash = props.graphql.constructor.hashFetchOptions(fetchOptions); | ||
_this.state.requestCache = props.graphql.cache[_this.state.fetchOptionsHash]; | ||
var fetchOptions = props.graphql.constructor.fetchOptions( | ||
_this.operation() | ||
) | ||
if (props.fetchOptionsOverride) props.fetchOptionsOverride(fetchOptions) | ||
_this.state.fetchOptionsHash = props.graphql.constructor.hashFetchOptions( | ||
fetchOptions | ||
) | ||
_this.state.requestCache = | ||
props.graphql.cache[_this.state.fetchOptionsHash] | ||
_this.props.graphql.onCacheUpdate(_this.state.fetchOptionsHash, _this.handleCacheUpdate); | ||
_this.props.graphql.onCacheUpdate( | ||
_this.state.fetchOptionsHash, | ||
_this.handleCacheUpdate | ||
) | ||
} | ||
return _this; | ||
return _this | ||
} | ||
var _proto = GraphQLQuery.prototype; | ||
var _proto = GraphQLQuery.prototype | ||
_proto.componentDidMount = function componentDidMount() { | ||
if (this.props.loadOnMount) this.load(); | ||
}; | ||
if (this.props.loadOnMount) this.load() | ||
} | ||
_proto.componentDidUpdate = function componentDidUpdate(_ref) { | ||
var query = _ref.query, | ||
variables = _ref.variables; | ||
if (this.props.loadOnReset && this.state.fetchOptionsHash && (query !== this.props.query || !(0, _fastDeepEqual.default)(variables, this.props.variables))) this.load(); | ||
}; | ||
variables = _ref.variables | ||
if ( | ||
this.props.loadOnReset && | ||
this.state.fetchOptionsHash && | ||
(query !== this.props.query || | ||
!(0, _fastDeepEqual.default)(variables, this.props.variables)) | ||
) | ||
this.load() | ||
} | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
if (this.state.fetchOptionsHash) this.props.graphql.offCacheUpdate(this.state.fetchOptionsHash, this.handleCacheUpdate); | ||
}; | ||
if (this.state.fetchOptionsHash) | ||
this.props.graphql.offCacheUpdate( | ||
this.state.fetchOptionsHash, | ||
this.handleCacheUpdate | ||
) | ||
} | ||
_proto.render = function render() { | ||
return this.props.children((0, _objectAssign.default)({ | ||
load: this.load, | ||
loading: this.state.loading | ||
}, this.state.requestCache)); | ||
}; | ||
return this.props.children( | ||
(0, _objectAssign.default)( | ||
{ | ||
load: this.load, | ||
loading: this.state.loading | ||
}, | ||
this.state.requestCache | ||
) | ||
) | ||
} | ||
return GraphQLQuery; | ||
}(_react.default.Component); | ||
_inheritsLoose(GraphQLQuery, _React$Component) | ||
return GraphQLQuery | ||
})(_react.default.Component) | ||
GraphQLQuery.propTypes = { | ||
@@ -134,13 +170,19 @@ graphql: _propTypes.default.instanceOf(_graphql.GraphQL).isRequired, | ||
children: _propTypes.default.func.isRequired | ||
}; | ||
} | ||
var Query = function Query(props) { | ||
return _react.default.createElement(Consumer, null, function (graphql) { | ||
return _react.default.createElement(GraphQLQuery, (0, _objectAssign.default)({ | ||
graphql: graphql | ||
}, props)); | ||
}); | ||
}; | ||
return _react.default.createElement(Consumer, null, function(graphql) { | ||
return _react.default.createElement( | ||
GraphQLQuery, | ||
(0, _objectAssign.default)( | ||
{ | ||
graphql: graphql | ||
}, | ||
props | ||
) | ||
) | ||
}) | ||
} | ||
exports.Query = Query; | ||
exports.Query = Query | ||
Query.propTypes = { | ||
@@ -154,2 +196,2 @@ fetchOptionsOverride: _propTypes.default.func, | ||
children: _propTypes.default.func.isRequired | ||
}; | ||
} |
@@ -1,111 +0,157 @@ | ||
"use strict"; | ||
'use strict' | ||
exports.__esModule = true; | ||
exports.GraphQL = void 0; | ||
exports.__esModule = true | ||
exports.GraphQL = void 0 | ||
var _fnv1a = _interopRequireDefault(require("fnv1a")); | ||
var _fnv1a = _interopRequireDefault(require('fnv1a')) | ||
var _extractFiles = _interopRequireDefault(require("extract-files")); | ||
var _extractFiles = _interopRequireDefault(require('extract-files')) | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { default: obj } | ||
} | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {} | ||
var target = {} | ||
var sourceKeys = Object.keys(source) | ||
var key, i | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i] | ||
if (excluded.indexOf(key) >= 0) continue | ||
target[key] = source[key] | ||
} | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source) | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i] | ||
if (excluded.indexOf(key) >= 0) continue | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue | ||
target[key] = source[key] | ||
} | ||
} | ||
return target | ||
} | ||
var GraphQL = function () { | ||
var GraphQL = (function() { | ||
function GraphQL(_temp) { | ||
var _this = this; | ||
var _this = this | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_ref$cache = _ref.cache, | ||
cache = _ref$cache === void 0 ? {} : _ref$cache; | ||
_ref$cache = _ref.cache, | ||
cache = _ref$cache === void 0 ? {} : _ref$cache | ||
this.requests = {}; | ||
this.listeners = {}; | ||
this.requests = {} | ||
this.listeners = {} | ||
this.onCacheUpdate = function (fetchOptionsHash, callback) { | ||
if (!_this.listeners[fetchOptionsHash]) _this.listeners[fetchOptionsHash] = []; | ||
this.onCacheUpdate = function(fetchOptionsHash, callback) { | ||
if (!_this.listeners[fetchOptionsHash]) | ||
_this.listeners[fetchOptionsHash] = [] | ||
_this.listeners[fetchOptionsHash].push(callback); | ||
}; | ||
_this.listeners[fetchOptionsHash].push(callback) | ||
} | ||
this.offCacheUpdate = function (fetchOptionsHash, callback) { | ||
this.offCacheUpdate = function(fetchOptionsHash, callback) { | ||
if (_this.listeners[fetchOptionsHash]) { | ||
_this.listeners[fetchOptionsHash] = _this.listeners[fetchOptionsHash].filter(function (listenerCallback) { | ||
return listenerCallback !== callback; | ||
}); | ||
if (!_this.listeners[fetchOptionsHash].length) delete _this.listeners[fetchOptionsHash]; | ||
_this.listeners[fetchOptionsHash] = _this.listeners[ | ||
fetchOptionsHash | ||
].filter(function(listenerCallback) { | ||
return listenerCallback !== callback | ||
}) | ||
if (!_this.listeners[fetchOptionsHash].length) | ||
delete _this.listeners[fetchOptionsHash] | ||
} | ||
}; | ||
} | ||
this.emitCacheUpdate = function (fetchOptionsHash, requestCache) { | ||
if (_this.listeners[fetchOptionsHash]) _this.listeners[fetchOptionsHash].forEach(function (callback) { | ||
return callback(requestCache); | ||
}); | ||
}; | ||
this.emitCacheUpdate = function(fetchOptionsHash, requestCache) { | ||
if (_this.listeners[fetchOptionsHash]) | ||
_this.listeners[fetchOptionsHash].forEach(function(callback) { | ||
return callback(requestCache) | ||
}) | ||
} | ||
this.reset = function (exceptFetchOptionsHash) { | ||
var fetchOptionsHashes = Object.keys(_this.cache); | ||
if (exceptFetchOptionsHash) fetchOptionsHashes = fetchOptionsHashes.filter(function (hash) { | ||
return hash !== exceptFetchOptionsHash; | ||
}); | ||
fetchOptionsHashes.forEach(function (fetchOptionsHash) { | ||
return delete _this.cache[fetchOptionsHash]; | ||
}); | ||
fetchOptionsHashes.forEach(function (fetchOptionsHash) { | ||
return _this.emitCacheUpdate(fetchOptionsHash); | ||
}); | ||
}; | ||
this.reset = function(exceptFetchOptionsHash) { | ||
var fetchOptionsHashes = Object.keys(_this.cache) | ||
if (exceptFetchOptionsHash) | ||
fetchOptionsHashes = fetchOptionsHashes.filter(function(hash) { | ||
return hash !== exceptFetchOptionsHash | ||
}) | ||
fetchOptionsHashes.forEach(function(fetchOptionsHash) { | ||
return delete _this.cache[fetchOptionsHash] | ||
}) | ||
fetchOptionsHashes.forEach(function(fetchOptionsHash) { | ||
return _this.emitCacheUpdate(fetchOptionsHash) | ||
}) | ||
} | ||
this.request = function (_ref2, fetchOptionsHash) { | ||
this.request = function(_ref2, fetchOptionsHash) { | ||
var url = _ref2.url, | ||
options = _objectWithoutProperties(_ref2, ["url"]); | ||
options = _objectWithoutProperties(_ref2, ['url']) | ||
var requestCache = {}; | ||
var fetcher = typeof fetch === 'function' ? fetch : function () { | ||
return Promise.reject(new Error('Global fetch API or polyfill unavailable.')); | ||
}; | ||
return (_this.requests[fetchOptionsHash] = fetcher(url, options)).then(function (response) { | ||
if (!response.ok) requestCache.httpError = { | ||
status: response.status, | ||
statusText: response.statusText | ||
}; | ||
return response.json().then(function (_ref3) { | ||
var errors = _ref3.errors, | ||
data = _ref3.data; | ||
if (!errors && !data) requestCache.parseError = 'Malformed payload.'; | ||
if (errors) requestCache.graphQLErrors = errors; | ||
if (data) requestCache.data = data; | ||
}, function (_ref4) { | ||
var message = _ref4.message; | ||
requestCache.parseError = message; | ||
}); | ||
}, function (_ref5) { | ||
var message = _ref5.message; | ||
requestCache.fetchError = message; | ||
}).then(function () { | ||
_this.cache[fetchOptionsHash] = requestCache; | ||
var requestCache = {} | ||
var fetcher = | ||
typeof fetch === 'function' | ||
? fetch | ||
: function() { | ||
return Promise.reject( | ||
new Error('Global fetch API or polyfill unavailable.') | ||
) | ||
} | ||
return (_this.requests[fetchOptionsHash] = fetcher(url, options)) | ||
.then( | ||
function(response) { | ||
if (!response.ok) | ||
requestCache.httpError = { | ||
status: response.status, | ||
statusText: response.statusText | ||
} | ||
return response.json().then( | ||
function(_ref3) { | ||
var errors = _ref3.errors, | ||
data = _ref3.data | ||
if (!errors && !data) | ||
requestCache.parseError = 'Malformed payload.' | ||
if (errors) requestCache.graphQLErrors = errors | ||
if (data) requestCache.data = data | ||
}, | ||
function(_ref4) { | ||
var message = _ref4.message | ||
requestCache.parseError = message | ||
} | ||
) | ||
}, | ||
function(_ref5) { | ||
var message = _ref5.message | ||
requestCache.fetchError = message | ||
} | ||
) | ||
.then(function() { | ||
_this.cache[fetchOptionsHash] = requestCache | ||
_this.emitCacheUpdate(fetchOptionsHash, requestCache); | ||
_this.emitCacheUpdate(fetchOptionsHash, requestCache) | ||
delete _this.requests[fetchOptionsHash]; | ||
return requestCache; | ||
}); | ||
}; | ||
delete _this.requests[fetchOptionsHash] | ||
return requestCache | ||
}) | ||
} | ||
this.query = function (_ref6) { | ||
this.query = function(_ref6) { | ||
var operation = _ref6.operation, | ||
fetchOptionsOverride = _ref6.fetchOptionsOverride, | ||
resetOnLoad = _ref6.resetOnLoad; | ||
fetchOptionsOverride = _ref6.fetchOptionsOverride, | ||
resetOnLoad = _ref6.resetOnLoad | ||
var fetchOptions = _this.constructor.fetchOptions(operation); | ||
var fetchOptions = _this.constructor.fetchOptions(operation) | ||
if (fetchOptionsOverride) fetchOptionsOverride(fetchOptions); | ||
if (fetchOptionsOverride) fetchOptionsOverride(fetchOptions) | ||
var fetchOptionsHash = _this.constructor.hashFetchOptions(fetchOptions); | ||
var fetchOptionsHash = _this.constructor.hashFetchOptions(fetchOptions) | ||
var request = _this.requests[fetchOptionsHash] || _this.request(fetchOptions, fetchOptionsHash); | ||
var request = | ||
_this.requests[fetchOptionsHash] || | ||
_this.request(fetchOptions, fetchOptionsHash) | ||
if (resetOnLoad) request.then(function () { | ||
return _this.reset(fetchOptionsHash); | ||
}); | ||
if (resetOnLoad) | ||
request.then(function() { | ||
return _this.reset(fetchOptionsHash) | ||
}) | ||
return { | ||
@@ -115,26 +161,31 @@ fetchOptionsHash: fetchOptionsHash, | ||
request: request | ||
}; | ||
}; | ||
} | ||
} | ||
this.cache = cache; | ||
this.cache = cache | ||
} | ||
GraphQL.requestBody = function requestBody(operation) { | ||
var files = (0, _extractFiles.default)(operation); | ||
var files = (0, _extractFiles.default)(operation) | ||
if (files.length) { | ||
var form = new FormData(); | ||
form.append('operations', JSON.stringify(operation)); | ||
form.append('map', JSON.stringify(files.reduce(function (map, _ref7, index) { | ||
var path = _ref7.path; | ||
map["" + index] = [path]; | ||
return map; | ||
}, {}))); | ||
files.forEach(function (_ref8, index) { | ||
var file = _ref8.file; | ||
return form.append(index, file, file.name); | ||
}); | ||
return form; | ||
} else return JSON.stringify(operation); | ||
}; | ||
var form = new FormData() | ||
form.append('operations', JSON.stringify(operation)) | ||
form.append( | ||
'map', | ||
JSON.stringify( | ||
files.reduce(function(map, _ref7, index) { | ||
var path = _ref7.path | ||
map['' + index] = [path] | ||
return map | ||
}, {}) | ||
) | ||
) | ||
files.forEach(function(_ref8, index) { | ||
var file = _ref8.file | ||
return form.append(index, file, file.name) | ||
}) | ||
return form | ||
} else return JSON.stringify(operation) | ||
} | ||
@@ -148,15 +199,16 @@ GraphQL.fetchOptions = function fetchOptions(operation) { | ||
} | ||
}; | ||
fetchOptions.body = this.requestBody(operation); | ||
if (typeof fetchOptions.body === 'string') fetchOptions.headers['Content-Type'] = 'application/json'; | ||
return fetchOptions; | ||
}; | ||
} | ||
fetchOptions.body = this.requestBody(operation) | ||
if (typeof fetchOptions.body === 'string') | ||
fetchOptions.headers['Content-Type'] = 'application/json' | ||
return fetchOptions | ||
} | ||
return GraphQL; | ||
}(); | ||
return GraphQL | ||
})() | ||
exports.GraphQL = GraphQL; | ||
exports.GraphQL = GraphQL | ||
GraphQL.hashFetchOptions = function (fetchOptions) { | ||
return (0, _fnv1a.default)(JSON.stringify(fetchOptions)).toString(36); | ||
}; | ||
GraphQL.hashFetchOptions = function(fetchOptions) { | ||
return (0, _fnv1a.default)(JSON.stringify(fetchOptions)).toString(36) | ||
} |
@@ -1,24 +0,24 @@ | ||
"use strict"; | ||
'use strict' | ||
exports.__esModule = true; | ||
exports.__esModule = true | ||
var _graphql = require("./graphql"); | ||
var _graphql = require('./graphql') | ||
Object.keys(_graphql).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _graphql[key]; | ||
}); | ||
Object.keys(_graphql).forEach(function(key) { | ||
if (key === 'default' || key === '__esModule') return | ||
exports[key] = _graphql[key] | ||
}) | ||
var _components = require("./components"); | ||
var _components = require('./components') | ||
Object.keys(_components).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _components[key]; | ||
}); | ||
Object.keys(_components).forEach(function(key) { | ||
if (key === 'default' || key === '__esModule') return | ||
exports[key] = _components[key] | ||
}) | ||
var _preload = require("./preload"); | ||
var _preload = require('./preload') | ||
Object.keys(_preload).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _preload[key]; | ||
}); | ||
Object.keys(_preload).forEach(function(key) { | ||
if (key === 'default' || key === '__esModule') return | ||
exports[key] = _preload[key] | ||
}) |
@@ -1,60 +0,101 @@ | ||
"use strict"; | ||
'use strict' | ||
exports.__esModule = true; | ||
exports.preload = preload; | ||
exports.__esModule = true | ||
exports.preload = preload | ||
var _objectAssign = _interopRequireDefault(require("object-assign")); | ||
var _objectAssign = _interopRequireDefault(require('object-assign')) | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { default: obj } | ||
} | ||
function preload(element) { | ||
var recursePreload = function recursePreload(rootElement, rootLegacyContext, loadRoot) { | ||
var recursePreload = function recursePreload( | ||
rootElement, | ||
rootLegacyContext, | ||
loadRoot | ||
) { | ||
if (rootLegacyContext === void 0) { | ||
rootLegacyContext = {}; | ||
rootLegacyContext = {} | ||
} | ||
if (loadRoot === void 0) { | ||
loadRoot = true; | ||
loadRoot = true | ||
} | ||
var loading = []; | ||
var loading = [] | ||
var recurse = function recurse(element, legacyContext) { | ||
if (!element) return; | ||
if (!element) return | ||
if (Array.isArray(element)) { | ||
element.forEach(function (item) { | ||
return recurse(item, legacyContext); | ||
}); | ||
return; | ||
element.forEach(function(item) { | ||
return recurse(item, legacyContext) | ||
}) | ||
return | ||
} | ||
if (element.type && (element.type.Consumer || typeof element.type === 'function')) { | ||
var props = (0, _objectAssign.default)({}, element.type.defaultProps, element.props); | ||
if (element.type.Consumer) recurse(element.props.children(element.type.currentValue), legacyContext);else if (element.type.prototype && (element.type.prototype.isReactComponent || element.type.prototype.isPureReactComponent)) { | ||
var instance = new element.type(props, legacyContext); | ||
instance.state = instance.state || null; | ||
if ( | ||
element.type && | ||
(element.type.Consumer || typeof element.type === 'function') | ||
) { | ||
var props = (0, _objectAssign.default)( | ||
{}, | ||
element.type.defaultProps, | ||
element.props | ||
) | ||
if (element.type.Consumer) | ||
recurse( | ||
element.props.children(element.type.currentValue), | ||
legacyContext | ||
) | ||
else if ( | ||
element.type.prototype && | ||
(element.type.prototype.isReactComponent || | ||
element.type.prototype.isPureReactComponent) | ||
) { | ||
var instance = new element.type(props, legacyContext) | ||
instance.state = instance.state || null | ||
instance.setState = function (newState) { | ||
if (typeof newState === 'function') newState = newState(instance.state, instance.props); | ||
instance.state = (0, _objectAssign.default)({}, instance.state, newState); | ||
}; | ||
instance.setState = function(newState) { | ||
if (typeof newState === 'function') | ||
newState = newState(instance.state, instance.props) | ||
instance.state = (0, _objectAssign.default)( | ||
{}, | ||
instance.state, | ||
newState | ||
) | ||
} | ||
if (instance.componentWillMount) instance.componentWillMount(); | ||
if (instance.getChildContext) legacyContext = (0, _objectAssign.default)({}, legacyContext, instance.getChildContext()); | ||
if (instance.constructor.name === 'GraphQLQuery' && element.props.loadOnMount && (element !== rootElement || loadRoot)) loading.push(instance.load().then(function () { | ||
return recursePreload(element, legacyContext, false); | ||
}));else recurse(instance.render(), legacyContext); | ||
} else recurse(element.type(props), legacyContext); | ||
if (instance.componentWillMount) instance.componentWillMount() | ||
if (instance.getChildContext) | ||
legacyContext = (0, _objectAssign.default)( | ||
{}, | ||
legacyContext, | ||
instance.getChildContext() | ||
) | ||
if ( | ||
instance.constructor.name === 'GraphQLQuery' && | ||
element.props.loadOnMount && | ||
(element !== rootElement || loadRoot) | ||
) | ||
loading.push( | ||
instance.load().then(function() { | ||
return recursePreload(element, legacyContext, false) | ||
}) | ||
) | ||
else recurse(instance.render(), legacyContext) | ||
} else recurse(element.type(props), legacyContext) | ||
} else if (element.props && element.props.children) { | ||
if (element.type._context) element.type._context.currentValue = element.props.value; | ||
recurse(element.props.children, legacyContext); | ||
if (element.type._context) | ||
element.type._context.currentValue = element.props.value | ||
recurse(element.props.children, legacyContext) | ||
} | ||
}; | ||
} | ||
recurse(rootElement, rootLegacyContext); | ||
return Promise.all(loading); | ||
}; | ||
recurse(rootElement, rootLegacyContext) | ||
return Promise.all(loading) | ||
} | ||
return recursePreload(element); | ||
} | ||
return recursePreload(element) | ||
} |
129
package.json
{ | ||
"name": "graphql-react", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A lightweight GraphQL client for React.", | ||
@@ -28,3 +28,4 @@ "license": "MIT", | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"!lib/test.*" | ||
], | ||
@@ -48,19 +49,18 @@ "main": "lib", | ||
"devDependencies": { | ||
"@babel/cli": "7.0.0-beta.44", | ||
"@babel/core": "7.0.0-beta.44", | ||
"@babel/plugin-proposal-class-properties": "7.0.0-beta.44", | ||
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.44", | ||
"@babel/preset-env": "7.0.0-beta.44", | ||
"@babel/preset-react": "7.0.0-beta.44", | ||
"ava": "^1.0.0-beta.4", | ||
"@babel/cli": "^7.0.0-beta.47", | ||
"@babel/core": "^7.0.0-beta.47", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.47", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.47", | ||
"@babel/preset-env": "^7.0.0-beta.47", | ||
"@babel/preset-react": "^7.0.0-beta.47", | ||
"babel-eslint": "^8.2.3", | ||
"babel-plugin-transform-replace-object-assign": "^2.0.0-beta.0", | ||
"cross-env": "^5.1.4", | ||
"cross-fetch": "^2.1.1", | ||
"documentation": "^6.3.2", | ||
"cross-fetch": "^2.2.0", | ||
"documentation": "^6.3.3", | ||
"eslint": "^4.19.1", | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-ava": "^4.5.1", | ||
"eslint-plugin-import": "^2.12.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-prettier": "^2.5.0", | ||
"eslint-plugin-react": "^7.7.0", | ||
"eslint-plugin-react": "^7.8.2", | ||
"express": "^4.16.3", | ||
@@ -71,4 +71,4 @@ "express-graphql": "^0.6.12", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.0.5", | ||
"npm-run-all": "^4.1.2", | ||
"lint-staged": "^7.1.2", | ||
"npm-run-all": "^4.1.3", | ||
"prettier": "^1.12.1", | ||
@@ -78,30 +78,22 @@ "react": "^16.3.2", | ||
"rimraf": "^2.6.2", | ||
"size-limit": "^0.17.0" | ||
"size-limit": "^0.18.1", | ||
"tap": "^12.0.1", | ||
"watch": "^1.0.2" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"prebuild": "npm run clean", | ||
"build": "run-p build:*", | ||
"build:clean": "rimraf lib", | ||
"build:js": "babel src -d lib", | ||
"build:mjs": "cross-env ESM=true babel src -d lib --keep-file-extension", | ||
"postbuild": "prettier 'lib/**/*.{mjs,js}' --write", | ||
"jsdoc": "documentation readme src -s API -c documentation.json --sort-order alpha -q", | ||
"postjsdoc": "prettier readme.md --write", | ||
"prewatch": "npm run build", | ||
"watch": "run-p watch:*", | ||
"watch:build": "run-p 'build:* -- --skip-initial-build --watch'", | ||
"watch:test": "ava -vw", | ||
"lint": "run-p lint:*", | ||
"build:mjs": "BABEL_ESM=1 babel src -d lib --keep-file-extension", | ||
"build:jsdoc": "documentation readme src --readme-file readme.md -s API -c documentation.json --sort-order alpha -q", | ||
"build:prettier": "prettier 'lib/**/*.{mjs,js}' readme.md --write", | ||
"lint:eslint": "eslint . --ext mjs,js", | ||
"lint:prettier": "prettier '**/*.{json,md}' -l", | ||
"lint:jsdoc": "documentation lint src", | ||
"fix": "run-p fix:*", | ||
"fix:eslint": "eslint . --ext mjs,js --fix", | ||
"fix:prettier": "prettier '**/*.{json,md}' --write", | ||
"presize": "npm run build", | ||
"size": "size-limit", | ||
"pretest": "npm run build", | ||
"test": "ava", | ||
"precommit": "lint-staged", | ||
"prepublishOnly": "run-s jsdoc lint size test" | ||
"lint:size": "size-limit", | ||
"tap:mjs": "node --experimental-modules --no-warnings lib/test | tap-mocha-reporter spec", | ||
"tap:js": "node lib/test | tap-mocha-reporter spec", | ||
"test": "FORCE_COLOR=1 TAP_COLORS=1 npm-run-all build:clean -p build:js build:mjs build:jsdoc -s build:prettier -p lint:* tap:* -c --aggregate-output --silent", | ||
"watch": "watch 'npm run test --silent' src --interval 1", | ||
"prepublishOnly": "npm run test", | ||
"precommit": "lint-staged" | ||
}, | ||
@@ -113,9 +105,11 @@ "lint-staged": { | ||
"eslintIgnore": [ | ||
"!.*", | ||
"node_modules", | ||
"lib", | ||
".next" | ||
"tap-snapshots" | ||
], | ||
"eslintConfig": { | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"sourceType": "script", | ||
"ecmaVersion": 2018 | ||
}, | ||
"env": { | ||
@@ -126,14 +120,16 @@ "es6": true, | ||
}, | ||
"plugins": [ | ||
"import", | ||
"node", | ||
"react", | ||
"prettier" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:import/recommended", | ||
"plugin:node/recommended", | ||
"plugin:react/recommended", | ||
"plugin:ava/recommended", | ||
"prettier", | ||
"prettier/react" | ||
], | ||
"plugins": [ | ||
"react", | ||
"ava", | ||
"prettier" | ||
], | ||
"rules": { | ||
@@ -147,2 +143,6 @@ "require-jsdoc": "warn", | ||
], | ||
"require-await": "error", | ||
"no-return-await": "error", | ||
"arrow-body-style": "error", | ||
"prefer-arrow-callback": "error", | ||
"curly": [ | ||
@@ -152,11 +152,20 @@ "error", | ||
], | ||
"prefer-destructuring": [ | ||
"error", | ||
{ | ||
"array": true, | ||
"object": true | ||
"prefer-destructuring": "error", | ||
"import/first": "error", | ||
"import/newline-after-import": "error", | ||
"import/no-useless-path-segments": "error", | ||
"import/order": "error", | ||
"node/no-unsupported-features": "off", | ||
"prettier/prettier": "error" | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.mjs" | ||
], | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
], | ||
"prettier/prettier": "error" | ||
} | ||
} | ||
] | ||
}, | ||
@@ -179,11 +188,3 @@ "prettier": { | ||
} | ||
], | ||
"ava": { | ||
"cache": false, | ||
"sources": [ | ||
"src/**/*.mjs", | ||
"!lib", | ||
"!example" | ||
] | ||
} | ||
] | ||
} |
@@ -1,2 +0,2 @@ | ||
![Logo](https://cdn.rawgit.com/jaydenseric/graphql-react/b2e60e80/graphql-react-logo.svg) | ||
![graphql-react logo](https://cdn.rawgit.com/jaydenseric/graphql-react/b2e60e80/graphql-react-logo.svg) | ||
@@ -56,3 +56,3 @@ # graphql-react | ||
See the [example GraphQL API and Next.js web app](example), deployed at [graphql-react.now.sh](https://graphql-react.now.sh). | ||
See the [example GraphQL API and Next.js web app](https://github.com/jaydenseric/graphql-react-examples), deployed at [graphql-react.now.sh](https://graphql-react.now.sh). | ||
@@ -59,0 +59,0 @@ ## Support |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
56786
848
30
5