graphql-hooks
Advanced tools
Comparing version 4.5.0 to 5.0.0
@@ -6,2 +6,16 @@ # Change Log | ||
# [5.0.0](https://github.com/nearform/graphql-hooks/compare/graphql-hooks@4.5.0...graphql-hooks@5.0.0) (2020-09-28) | ||
### Bug Fixes | ||
* publishing with lerna ([3b566dc](https://github.com/nearform/graphql-hooks/commit/3b566dcf3123d432c8d1e48eaac2743e4eb886a1)) | ||
* response data is optional ([#567](https://github.com/nearform/graphql-hooks/issues/567)) ([975914a](https://github.com/nearform/graphql-hooks/commit/975914aa2948fb0787e7cfe40a82dc7acb53cb8d)) | ||
* **deps:** update dependency dequal to v2 ([#546](https://github.com/nearform/graphql-hooks/issues/546)) ([eca16e6](https://github.com/nearform/graphql-hooks/commit/eca16e616655f0ed76a27b252a7ce101abd64433)) | ||
* **deps:** update dependency extract-files to v9 ([#542](https://github.com/nearform/graphql-hooks/issues/542)) ([ba0a3f6](https://github.com/nearform/graphql-hooks/commit/ba0a3f6893bc4aa49a0b69d7af823f76e8ed5963)) | ||
# [4.5.0](https://github.com/nearform/graphql-hooks/compare/graphql-hooks@4.4.4...graphql-hooks@4.5.0) (2020-06-19) | ||
@@ -8,0 +22,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(global = global || self, factory(global.GraphQLHooks = {}, global.React)); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GraphQLHooks = {}, global.React)); | ||
}(this, (function (exports, React) { 'use strict'; | ||
var React__default = 'default' in React ? React['default'] : React; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
function _defineProperty(obj, key, value) { | ||
@@ -58,3 +60,3 @@ if (key in obj) { | ||
var ClientContext = React__default.createContext(); | ||
var ClientContext = React__default['default'].createContext(); | ||
ClientContext.displayName = 'ClientContext'; | ||
@@ -410,18 +412,84 @@ | ||
var has = Object.prototype.hasOwnProperty; | ||
function find(iter, tar, key) { | ||
for (key of iter.keys()) { | ||
if (dequal(key, tar)) return key; | ||
} | ||
} | ||
function dequal(foo, bar) { | ||
var ctor, len; | ||
var ctor, len, tmp; | ||
if (foo === bar) return true; | ||
if (foo && bar && (ctor=foo.constructor) === bar.constructor) { | ||
if (ctor === Date) return foo.getTime() === bar.getTime(); | ||
if (ctor === RegExp) return foo.toString() === bar.toString(); | ||
if (ctor === Array && (len=foo.length) === bar.length) { | ||
while (len-- && dequal(foo[len], bar[len])); | ||
if (ctor === Array) { | ||
if ((len=foo.length) === bar.length) { | ||
while (len-- && dequal(foo[len], bar[len])); | ||
} | ||
return len === -1; | ||
} | ||
if (ctor === Object) { | ||
if (Object.keys(foo).length !== Object.keys(bar).length) return false; | ||
for (len in foo) if (!(len in bar) || !dequal(foo[len], bar[len])) return false; | ||
if (ctor === Set) { | ||
if (foo.size !== bar.size) { | ||
return false; | ||
} | ||
for (len of foo) { | ||
tmp = len; | ||
if (tmp && typeof tmp === 'object') { | ||
tmp = find(bar, tmp); | ||
if (!tmp) return false; | ||
} | ||
if (!bar.has(tmp)) return false; | ||
} | ||
return true; | ||
} | ||
if (ctor === Map) { | ||
if (foo.size !== bar.size) { | ||
return false; | ||
} | ||
for (len of foo) { | ||
tmp = len[0]; | ||
if (tmp && typeof tmp === 'object') { | ||
tmp = find(bar, tmp); | ||
if (!tmp) return false; | ||
} | ||
if (!dequal(len[1], bar.get(tmp))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
if (ctor === ArrayBuffer) { | ||
foo = new Uint8Array(foo); | ||
bar = new Uint8Array(bar); | ||
} else if (ctor === DataView) { | ||
if ((len=foo.byteLength) === bar.byteLength) { | ||
while (len-- && foo.getInt8(len) === bar.getInt8(len)); | ||
} | ||
return len === -1; | ||
} | ||
if (ArrayBuffer.isView(foo)) { | ||
if ((len=foo.byteLength) === bar.byteLength) { | ||
while (len-- && foo[len] === bar[len]); | ||
} | ||
return len === -1; | ||
} | ||
if (!ctor || typeof foo === 'object') { | ||
len = 0; | ||
for (ctor in foo) { | ||
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false; | ||
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false; | ||
} | ||
return Object.keys(bar).length === len; | ||
} | ||
} | ||
return foo !== foo && bar !== bar; | ||
@@ -484,3 +552,3 @@ } | ||
function useDeepCompareCallback(callback, deps) { | ||
var ref = React__default.useRef(); | ||
var ref = React__default['default'].useRef(); | ||
@@ -491,3 +559,3 @@ if (!dequal(deps, ref.current)) { | ||
return React__default.useCallback(callback, ref.current); | ||
return React__default['default'].useCallback(callback, ref.current); | ||
} | ||
@@ -513,6 +581,6 @@ /* | ||
var contextClient = React__default.useContext(ClientContext); | ||
var contextClient = React__default['default'].useContext(ClientContext); | ||
var client = initialOpts.client || contextClient; | ||
var isMounted = React__default.useRef(true); | ||
var activeCacheKey = React__default.useRef(null); | ||
var isMounted = React__default['default'].useRef(true); | ||
var activeCacheKey = React__default['default'].useRef(null); | ||
var operation = { | ||
@@ -540,3 +608,3 @@ query: query, | ||
var _React$useReducer = React__default.useReducer(reducer, initialState), | ||
var _React$useReducer = React__default['default'].useReducer(reducer, initialState), | ||
state = _React$useReducer[0], | ||
@@ -549,3 +617,3 @@ dispatch = _React$useReducer[1]; // NOTE: state from useReducer is only initialState on the first render | ||
var stringifiedCacheKey = JSON.stringify(cacheKey); | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
if (!initialOpts.updateData) { | ||
@@ -560,3 +628,3 @@ // if using updateData we can assume that the consumer cares about the previous data | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
isMounted.current = true; | ||
@@ -631,3 +699,3 @@ return function () { | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
if (state.useCache) { | ||
@@ -663,6 +731,6 @@ client.saveCache(state.cacheKey, state); | ||
var contextClient = React__default.useContext(ClientContext); | ||
var contextClient = React__default['default'].useContext(ClientContext); | ||
var client = opts.client || contextClient; | ||
var _React$useState = React__default.useState(false), | ||
var _React$useState = React__default['default'].useState(false), | ||
calledDuringSSR = _React$useState[0], | ||
@@ -686,3 +754,3 @@ setCalledDuringSSR = _React$useState[1]; | ||
var stringifiedAllOpts = JSON.stringify(allOpts); | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
queryReq(); | ||
@@ -692,3 +760,3 @@ }, [query, stringifiedAllOpts]); // eslint-disable-line react-hooks/exhaustive-deps | ||
return _objectSpread2(_objectSpread2({}, state), {}, { | ||
refetch: React__default.useCallback(function (options) { | ||
refetch: React__default['default'].useCallback(function (options) { | ||
if (options === void 0) { | ||
@@ -695,0 +763,0 @@ options = {}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).GraphQLHooks={},e.React)}(this,(function(e,t){"use strict";var r="default"in t?t.default:t;function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var a=r.createContext();a.displayName="ClientContext";var s=function(e){var t=e.name,r=e.type;this.uri=e.uri,this.name=t,this.type=r},u=function(e){return"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof s},c=function(e){return u(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe},f=function(){function e(e){if(void 0===e&&(e={}),!e.url)throw Error("GraphQLClient: config.url is required");if(e.fetch&&"function"!=typeof e.fetch)throw Error("GraphQLClient: config.fetch must be a function");if(!e.fetch&&!fetch)throw Error("GraphQLClient: fetch must be polyfilled or passed in new GraphQLClient({ fetch })");if(e.ssrMode&&!e.cache)throw Error("GraphQLClient: config.cache is required when in ssrMode");this.cache=e.cache,this.headers=e.headers||{},this.ssrMode=e.ssrMode,this.ssrPromises=[],this.url=e.url,this.fetch=e.fetch||fetch.bind(),this.fetchOptions=e.fetchOptions||{},this.FormData=e.FormData||("undefined"!=typeof FormData?FormData:void 0),this.logErrors=void 0===e.logErrors||e.logErrors,this.onError=e.onError,this.useGETForQueries=!0===e.useGETForQueries,this.subscriptionClient=e.subscriptionClient}var t=e.prototype;return t.setHeader=function(e,t){return this.headers[e]=t,this},t.setHeaders=function(e){return this.headers=e,this},t.removeHeader=function(e){return delete this.headers[e],this},t.logErrorResult=function(e){var t=e.result,r=e.operation;console.error("GraphQL Hooks Error"),console.groupCollapsed("---\x3e Full Error Details"),console.groupCollapsed("Operation:"),console.log(r),console.groupEnd();var n=t.error;n&&(n.fetchError&&(console.groupCollapsed("FETCH ERROR:"),console.log(n.fetchError),console.groupEnd()),n.httpError&&(console.groupCollapsed("HTTP ERROR:"),console.log(n.httpError),console.groupEnd()),n.graphQLErrors&&n.graphQLErrors.length>0&&(console.groupCollapsed("GRAPHQL ERROR:"),n.graphQLErrors.forEach((function(e){return console.log(e)})),console.groupEnd())),console.groupEnd()},t.generateResult=function(e){var t=e.fetchError,r=e.httpError,n=e.graphQLErrors,o=e.data;return!!(n&&n.length>0||t||r)?{data:o,error:{fetchError:t,httpError:r,graphQLErrors:n}}:{data:o}},t.getCacheKey=function(e,t){return void 0===t&&(t={}),{operation:e,fetchOptions:i(i({},this.fetchOptions),t.fetchOptionsOverrides)}},t.getCache=function(e){var t=this.cache?this.cache.get(e):null;if(t)return t},t.saveCache=function(e,t){this.cache&&this.cache.set(e,t)},t.getFetchOptions=function(e,t){void 0===t&&(t={});var r=i(i({method:"POST",headers:i({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;var n=function e(t,r,n){var o;void 0===r&&(r=""),void 0===n&&(n=u);var i=new Map;function a(e,t){var r=i.get(t);r?r.push.apply(r,e):i.set(t,e)}if(n(t))o=null,a([r],t);else{var s=r?r+".":"";if("undefined"!=typeof FileList&&t instanceof FileList)o=Array.prototype.map.call(t,(function(e,t){return a([""+s+t],e),null}));else if(Array.isArray(t))o=t.map((function(t,r){var o=e(t,""+s+r,n);return o.files.forEach(a),o.clone}));else if(t&&t.constructor===Object)for(var c in o={},t){var f=e(t[c],""+s+c,n);f.files.forEach(a),o[c]=f.clone}else o=t}return{clone:o,files:i}}(e,"",c),o=n.files,a=JSON.stringify(n.clone);if(o.size){if(!this.FormData)throw Error("GraphQLClient: FormData must be polyfilled or passed in new GraphQLClient({ FormData })");var s=new this.FormData;s.append("operations",a);var f={},l=0;o.forEach((function(e){f[++l]=e})),s.append("map",JSON.stringify(f)),l=0,o.forEach((function(e,t){s.append(""+ ++l,t,t.name)})),r.body=s}else r.headers["Content-Type"]="application/json",r.body=a;return r},t.request=function(e,t){var r=this;void 0===t&&(t={});var n=this.url;"GET"===this.getFetchOptions(e,t.fetchOptionsOverrides).method&&(n=n+"?"+Object.entries(e).filter((function(e){return!!e[1]})).map((function(e){var t=e[0],r=e[1];return"variables"===t&&(r=JSON.stringify(r)),t+"="+encodeURIComponent(r)})).join("&"));return this.fetch(n,this.getFetchOptions(e,t.fetchOptionsOverrides)).then((function(e){return e.ok?e.json().then((function(e){return r.generateResult({graphQLErrors:e.errors,data:e.data})})):e.text().then((function(t){return r.generateResult({httpError:{status:e.status,statusText:e.statusText,body:t}})}))})).catch((function(e){return r.generateResult({fetchError:e})})).then((function(t){return t.error&&(r.logErrors&&r.logErrorResult({result:t,operation:e}),r.onError&&r.onError({result:t,operation:e})),t}))},t.createSubscription=function(e){if(!this.subscriptionClient)throw Error("No SubscriptionClient! Please set in the constructor.");return this.subscriptionClient.request(e)},e}();var l="RESET_STATE",h="LOADING",p="CACHE_HIT",d="REQUEST_RESULT";function g(e,t){switch(t.type){case l:return t.initialState;case h:return e.error?i(i({},t.initialState),{},{data:e.data,loading:!0}):e.loading?e:i(i({},e),{},{loading:!0});case p:return e.cacheHit&&!t.resetState?e:i(i({},t.result),{},{cacheHit:!0,loading:!1});case d:return i(i({},t.result),{},{data:e.data&&t.result.data&&t.updateData?t.updateData(e.data,t.result.data):t.result.data,cacheHit:!1,loading:!1});default:return e}}function v(e,t){var n=r.useRef();return function e(t,r){var n,o;if(t===r)return!0;if(t&&r&&(n=t.constructor)===r.constructor){if(n===Date)return t.getTime()===r.getTime();if(n===RegExp)return""+t==""+r;if(n===Array&&(o=t.length)===r.length){for(;o--&&e(t[o],r[o]););return-1===o}if(n===Object){if(Object.keys(t).length!==Object.keys(r).length)return!1;for(o in t)if(!(o in r)||!e(t[o],r[o]))return!1;return!0}}return t!=t&&r!=r}(t,n.current)||(n.current=t),r.useCallback(e,n.current)}function E(e,t){if(void 0===t&&(t={}),"string"!=typeof e)throw Error("Your query must be a string. If you are using the `gql` template literal from graphql-tag, remove it from your query.");var n=r.useContext(a),o=t.client||n,s=r.useRef(!0),u=r.useRef(null),c={query:e,variables:t.variables,operationName:t.operationName,persisted:t.persisted};(t.persisted||o.useGETForQueries&&!t.isMutation)&&(t.fetchOptionsOverrides=i(i({},t.fetchOptionsOverrides),{},{method:"GET"}));var f=o.getCacheKey(c,t),E=t.isMutation||t.isManual,y=t.skipCache||!o.cache?null:o.cache.get(f),b=i(i({},y),{},{cacheHit:!!y,loading:!E&&!y}),O=r.useReducer(g,b),C=O[0],m=O[1],R=JSON.stringify(f);r.useEffect((function(){t.updateData||m({type:l,initialState:b})}),[R]),r.useEffect((function(){return s.current=!0,function(){s.current=!1}}),[]);var D=v((function(e){if(!s.current)return Promise.resolve();var r=i(i({},t),e),n=i(i({},c),{},{variables:r.variables,operationName:r.operationName}),a=o.getCacheKey(n,r);u.current=a;var f=r.skipCache?null:o.getCache(a);return f?(m({type:p,result:f,resetState:R!==JSON.stringify(C.cacheKey)}),Promise.resolve(f)):(m({type:h,initialState:b}),o.request(n,r).then((function(e){if(r.updateData&&"function"!=typeof r.updateData)throw Error("options.updateData must be a function");var t=i({},e);if(r.useCache&&(t.useCache=!0,t.cacheKey=a,o.ssrMode)){var n={error:t.error,data:r.updateData?r.updateData(C.data,t.data):t.data};o.saveCache(a,n)}return s.current&&a===u.current&&m({type:d,updateData:r.updateData,result:t}),e})))}),[o,t,c]);r.useEffect((function(){C.useCache&&o.saveCache(C.cacheKey,C)}),[o,C]);return[D,C,function(e){return void 0===e&&(e={}),m({type:l,initialState:i(i({},b),e)})}]}var y={useCache:!0};e.ClientContext=a,e.GraphQLClient=f,e.useClientRequest=E,e.useManualQuery=function(e,t){return E(e,i({useCache:!0,isManual:!0},t))},e.useMutation=function(e,t){return E(e,i({isMutation:!0},t))},e.useQuery=function(e,t){void 0===t&&(t={});var n=i(i({},y),t),o=r.useContext(a),s=t.client||o,u=r.useState(!1),c=u[0],f=u[1],l=E(e,n),h=l[0],p=l[1];if(s.ssrMode&&!1!==t.ssr&&!c&&!t.skipCache){if(!p.data&&!p.error){var d=h();s.ssrPromises.push(d)}f(!0)}var g=JSON.stringify(n);return r.useEffect((function(){h()}),[e,g]),i(i({},p),{},{refetch:r.useCallback((function(e){return void 0===e&&(e={}),h(i({skipCache:!0,updateData:function(e,t){return t}},e))}),[h])})},e.useSubscription=function(e,r){var n=t.useRef(r);n.current=r;var o=t.useContext(a),i=e.client||o,s={query:e.query,variables:e.variables};t.useEffect((function(){var e=i.createSubscription(s).subscribe({next:function(e){n.current(e)},error:function(){e.unsubscribe()},complete:function(){e.unsubscribe()}});return function(){e.unsubscribe()}}),[])},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GraphQLHooks={},e.React)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var s=n.default.createContext();s.displayName="ClientContext";var u=function(e){var t=e.name,r=e.type;this.uri=e.uri,this.name=t,this.type=r},c=function(e){return"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof u},f=function e(t,r,n){var o;void 0===r&&(r=""),void 0===n&&(n=c);var i=new Map;function a(e,t){var r=i.get(t);r?r.push.apply(r,e):i.set(t,e)}if(n(t))o=null,a([r],t);else{var s=r?r+".":"";if("undefined"!=typeof FileList&&t instanceof FileList)o=Array.prototype.map.call(t,(function(e,t){return a([""+s+t],e),null}));else if(Array.isArray(t))o=t.map((function(t,r){var o=e(t,""+s+r,n);return o.files.forEach(a),o.clone}));else if(t&&t.constructor===Object)for(var u in o={},t){var f=e(t[u],""+s+u,n);f.files.forEach(a),o[u]=f.clone}else o=t}return{clone:o,files:i}},l=function(e){return c(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe},h=function(){function e(e){if(void 0===e&&(e={}),!e.url)throw Error("GraphQLClient: config.url is required");if(e.fetch&&"function"!=typeof e.fetch)throw Error("GraphQLClient: config.fetch must be a function");if(!e.fetch&&!fetch)throw Error("GraphQLClient: fetch must be polyfilled or passed in new GraphQLClient({ fetch })");if(e.ssrMode&&!e.cache)throw Error("GraphQLClient: config.cache is required when in ssrMode");this.cache=e.cache,this.headers=e.headers||{},this.ssrMode=e.ssrMode,this.ssrPromises=[],this.url=e.url,this.fetch=e.fetch||fetch.bind(),this.fetchOptions=e.fetchOptions||{},this.FormData=e.FormData||("undefined"!=typeof FormData?FormData:void 0),this.logErrors=void 0===e.logErrors||e.logErrors,this.onError=e.onError,this.useGETForQueries=!0===e.useGETForQueries,this.subscriptionClient=e.subscriptionClient}var t=e.prototype;return t.setHeader=function(e,t){return this.headers[e]=t,this},t.setHeaders=function(e){return this.headers=e,this},t.removeHeader=function(e){return delete this.headers[e],this},t.logErrorResult=function(e){var t=e.result,r=e.operation;console.error("GraphQL Hooks Error"),console.groupCollapsed("---\x3e Full Error Details"),console.groupCollapsed("Operation:"),console.log(r),console.groupEnd();var n=t.error;n&&(n.fetchError&&(console.groupCollapsed("FETCH ERROR:"),console.log(n.fetchError),console.groupEnd()),n.httpError&&(console.groupCollapsed("HTTP ERROR:"),console.log(n.httpError),console.groupEnd()),n.graphQLErrors&&n.graphQLErrors.length>0&&(console.groupCollapsed("GRAPHQL ERROR:"),n.graphQLErrors.forEach((function(e){return console.log(e)})),console.groupEnd())),console.groupEnd()},t.generateResult=function(e){var t=e.fetchError,r=e.httpError,n=e.graphQLErrors,o=e.data;return!!(n&&n.length>0||t||r)?{data:o,error:{fetchError:t,httpError:r,graphQLErrors:n}}:{data:o}},t.getCacheKey=function(e,t){return void 0===t&&(t={}),{operation:e,fetchOptions:a(a({},this.fetchOptions),t.fetchOptionsOverrides)}},t.getCache=function(e){var t=this.cache?this.cache.get(e):null;if(t)return t},t.saveCache=function(e,t){this.cache&&this.cache.set(e,t)},t.getFetchOptions=function(e,t){void 0===t&&(t={});var r=a(a({method:"POST",headers:a({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;var n=f(e,"",l),o=n.files,i=JSON.stringify(n.clone);if(o.size){if(!this.FormData)throw Error("GraphQLClient: FormData must be polyfilled or passed in new GraphQLClient({ FormData })");var s=new this.FormData;s.append("operations",i);var u={},c=0;o.forEach((function(e){u[++c]=e})),s.append("map",JSON.stringify(u)),c=0,o.forEach((function(e,t){s.append(""+ ++c,t,t.name)})),r.body=s}else r.headers["Content-Type"]="application/json",r.body=i;return r},t.request=function(e,t){var r=this;void 0===t&&(t={});var n=this.url;"GET"===this.getFetchOptions(e,t.fetchOptionsOverrides).method&&(n=n+"?"+Object.entries(e).filter((function(e){return!!e[1]})).map((function(e){var t=e[0],r=e[1];return"variables"===t&&(r=JSON.stringify(r)),t+"="+encodeURIComponent(r)})).join("&"));return this.fetch(n,this.getFetchOptions(e,t.fetchOptionsOverrides)).then((function(e){return e.ok?e.json().then((function(e){return r.generateResult({graphQLErrors:e.errors,data:e.data})})):e.text().then((function(t){return r.generateResult({httpError:{status:e.status,statusText:e.statusText,body:t}})}))})).catch((function(e){return r.generateResult({fetchError:e})})).then((function(t){return t.error&&(r.logErrors&&r.logErrorResult({result:t,operation:e}),r.onError&&r.onError({result:t,operation:e})),t}))},t.createSubscription=function(e){if(!this.subscriptionClient)throw Error("No SubscriptionClient! Please set in the constructor.");return this.subscriptionClient.request(e)},e}(),p=Object.prototype.hasOwnProperty;function d(e,t,r){for(r of e.keys())if(g(r,t))return r}function g(e,t){var r,n,o;if(e===t)return!0;if(e&&t&&(r=e.constructor)===t.constructor){if(r===Date)return e.getTime()===t.getTime();if(r===RegExp)return""+e==""+t;if(r===Array){if((n=e.length)===t.length)for(;n--&&g(e[n],t[n]););return-1===n}if(r===Set){if(e.size!==t.size)return!1;for(n of e){if((o=n)&&"object"==typeof o&&!(o=d(t,o)))return!1;if(!t.has(o))return!1}return!0}if(r===Map){if(e.size!==t.size)return!1;for(n of e){if((o=n[0])&&"object"==typeof o&&!(o=d(t,o)))return!1;if(!g(n[1],t.get(o)))return!1}return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((n=e.byteLength)===t.byteLength)for(;n--&&e.getInt8(n)===t.getInt8(n););return-1===n}if(ArrayBuffer.isView(e)){if((n=e.byteLength)===t.byteLength)for(;n--&&e[n]===t[n];);return-1===n}if(!r||"object"==typeof e){for(r in n=0,e){if(p.call(e,r)&&++n&&!p.call(t,r))return!1;if(!(r in t)||!g(e[r],t[r]))return!1}return Object.keys(t).length===n}}return e!=e&&t!=t}var y="RESET_STATE",v="LOADING",b="CACHE_HIT",E="REQUEST_RESULT";function O(e,t){switch(t.type){case y:return t.initialState;case v:return e.error?a(a({},t.initialState),{},{data:e.data,loading:!0}):e.loading?e:a(a({},e),{},{loading:!0});case b:return e.cacheHit&&!t.resetState?e:a(a({},t.result),{},{cacheHit:!0,loading:!1});case E:return a(a({},t.result),{},{data:e.data&&t.result.data&&t.updateData?t.updateData(e.data,t.result.data):t.result.data,cacheHit:!1,loading:!1});default:return e}}function C(e,t){if(void 0===t&&(t={}),"string"!=typeof e)throw Error("Your query must be a string. If you are using the `gql` template literal from graphql-tag, remove it from your query.");var r=n.default.useContext(s),o=t.client||r,i=n.default.useRef(!0),u=n.default.useRef(null),c={query:e,variables:t.variables,operationName:t.operationName,persisted:t.persisted};(t.persisted||o.useGETForQueries&&!t.isMutation)&&(t.fetchOptionsOverrides=a(a({},t.fetchOptionsOverrides),{},{method:"GET"}));var f=o.getCacheKey(c,t),l=t.isMutation||t.isManual,h=t.skipCache||!o.cache?null:o.cache.get(f),p=a(a({},h),{},{cacheHit:!!h,loading:!l&&!h}),d=n.default.useReducer(O,p),C=d[0],m=d[1],R=JSON.stringify(f);n.default.useEffect((function(){t.updateData||m({type:y,initialState:p})}),[R]),n.default.useEffect((function(){return i.current=!0,function(){i.current=!1}}),[]);var D,j,w,S=(D=function(e){if(!i.current)return Promise.resolve();var r=a(a({},t),e),n=a(a({},c),{},{variables:r.variables,operationName:r.operationName}),s=o.getCacheKey(n,r);u.current=s;var f=r.skipCache?null:o.getCache(s);return f?(m({type:b,result:f,resetState:R!==JSON.stringify(C.cacheKey)}),Promise.resolve(f)):(m({type:v,initialState:p}),o.request(n,r).then((function(e){if(r.updateData&&"function"!=typeof r.updateData)throw Error("options.updateData must be a function");var t=a({},e);if(r.useCache&&(t.useCache=!0,t.cacheKey=s,o.ssrMode)){var n={error:t.error,data:r.updateData?r.updateData(C.data,t.data):t.data};o.saveCache(s,n)}return i.current&&s===u.current&&m({type:E,updateData:r.updateData,result:t}),e})))},j=[o,t,c],w=n.default.useRef(),g(j,w.current)||(w.current=j),n.default.useCallback(D,w.current));n.default.useEffect((function(){C.useCache&&o.saveCache(C.cacheKey,C)}),[o,C]);return[S,C,function(e){return void 0===e&&(e={}),m({type:y,initialState:a(a({},p),e)})}]}var m={useCache:!0};e.ClientContext=s,e.GraphQLClient=h,e.useClientRequest=C,e.useManualQuery=function(e,t){return C(e,a({useCache:!0,isManual:!0},t))},e.useMutation=function(e,t){return C(e,a({isMutation:!0},t))},e.useQuery=function(e,t){void 0===t&&(t={});var r=a(a({},m),t),o=n.default.useContext(s),i=t.client||o,u=n.default.useState(!1),c=u[0],f=u[1],l=C(e,r),h=l[0],p=l[1];if(i.ssrMode&&!1!==t.ssr&&!c&&!t.skipCache){if(!p.data&&!p.error){var d=h();i.ssrPromises.push(d)}f(!0)}var g=JSON.stringify(r);return n.default.useEffect((function(){h()}),[e,g]),a(a({},p),{},{refetch:n.default.useCallback((function(e){return void 0===e&&(e={}),h(a({skipCache:!0,updateData:function(e,t){return t}},e))}),[h])})},e.useSubscription=function(e,r){var n=t.useRef(r);n.current=r;var o=t.useContext(s),i=e.client||o,a={query:e.query,variables:e.variables};t.useEffect((function(){var e=i.createSubscription(a).subscribe({next:function(e){n.current(e)},error:function(){e.unsubscribe()},complete:function(){e.unsubscribe()}});return function(){e.unsubscribe()}}),[])},Object.defineProperty(e,"__esModule",{value:!0})})); |
import React, { useRef, useContext, useEffect } from 'react'; | ||
import { isExtractableFile, extractFiles } from 'extract-files'; | ||
import deepEqual from 'dequal'; | ||
import { dequal } from 'dequal'; | ||
@@ -393,3 +393,3 @@ function _defineProperty(obj, key, value) { | ||
if (!deepEqual(deps, ref.current)) { | ||
if (!dequal(deps, ref.current)) { | ||
ref.current = deps; | ||
@@ -396,0 +396,0 @@ } |
@@ -188,3 +188,3 @@ import * as React from 'react' | ||
cacheHit: boolean | ||
data: ResponseData | ||
data?: ResponseData | ||
error?: APIError<TGraphQLError> | ||
@@ -191,0 +191,0 @@ } |
@@ -5,9 +5,10 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var React = require('react'); | ||
var React__default = _interopDefault(React); | ||
var extractFiles = require('extract-files'); | ||
var deepEqual = _interopDefault(require('dequal')); | ||
var dequal = require('dequal'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
function _defineProperty(obj, key, value) { | ||
@@ -62,3 +63,3 @@ if (key in obj) { | ||
var ClientContext = React__default.createContext(); | ||
var ClientContext = React__default['default'].createContext(); | ||
ClientContext.displayName = 'ClientContext'; | ||
@@ -400,9 +401,9 @@ | ||
function useDeepCompareCallback(callback, deps) { | ||
var ref = React__default.useRef(); | ||
var ref = React__default['default'].useRef(); | ||
if (!deepEqual(deps, ref.current)) { | ||
if (!dequal.dequal(deps, ref.current)) { | ||
ref.current = deps; | ||
} | ||
return React__default.useCallback(callback, ref.current); | ||
return React__default['default'].useCallback(callback, ref.current); | ||
} | ||
@@ -428,6 +429,6 @@ /* | ||
var contextClient = React__default.useContext(ClientContext); | ||
var contextClient = React__default['default'].useContext(ClientContext); | ||
var client = initialOpts.client || contextClient; | ||
var isMounted = React__default.useRef(true); | ||
var activeCacheKey = React__default.useRef(null); | ||
var isMounted = React__default['default'].useRef(true); | ||
var activeCacheKey = React__default['default'].useRef(null); | ||
var operation = { | ||
@@ -455,3 +456,3 @@ query: query, | ||
var _React$useReducer = React__default.useReducer(reducer, initialState), | ||
var _React$useReducer = React__default['default'].useReducer(reducer, initialState), | ||
state = _React$useReducer[0], | ||
@@ -464,3 +465,3 @@ dispatch = _React$useReducer[1]; // NOTE: state from useReducer is only initialState on the first render | ||
var stringifiedCacheKey = JSON.stringify(cacheKey); | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
if (!initialOpts.updateData) { | ||
@@ -475,3 +476,3 @@ // if using updateData we can assume that the consumer cares about the previous data | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
isMounted.current = true; | ||
@@ -546,3 +547,3 @@ return function () { | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
if (state.useCache) { | ||
@@ -578,6 +579,6 @@ client.saveCache(state.cacheKey, state); | ||
var contextClient = React__default.useContext(ClientContext); | ||
var contextClient = React__default['default'].useContext(ClientContext); | ||
var client = opts.client || contextClient; | ||
var _React$useState = React__default.useState(false), | ||
var _React$useState = React__default['default'].useState(false), | ||
calledDuringSSR = _React$useState[0], | ||
@@ -601,3 +602,3 @@ setCalledDuringSSR = _React$useState[1]; | ||
var stringifiedAllOpts = JSON.stringify(allOpts); | ||
React__default.useEffect(function () { | ||
React__default['default'].useEffect(function () { | ||
queryReq(); | ||
@@ -607,3 +608,3 @@ }, [query, stringifiedAllOpts]); // eslint-disable-line react-hooks/exhaustive-deps | ||
return _objectSpread2(_objectSpread2({}, state), {}, { | ||
refetch: React__default.useCallback(function (options) { | ||
refetch: React__default['default'].useCallback(function (options) { | ||
if (options === void 0) { | ||
@@ -610,0 +611,0 @@ options = {}; |
{ | ||
"name": "graphql-hooks", | ||
"version": "4.5.0", | ||
"version": "5.0.0", | ||
"description": "Graphql Hooks", | ||
@@ -37,11 +37,11 @@ "main": "lib/graphql-hooks.js", | ||
"dependencies": { | ||
"dequal": "^1.0.0", | ||
"extract-files": "^8.0.0" | ||
"dequal": "^2.0.0", | ||
"extract-files": "^9.0.0" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react": "^10.0.0", | ||
"@testing-library/react": "^11.0.0", | ||
"@testing-library/react-hooks": "^3.2.1", | ||
"formdata-node": "^2.0.0", | ||
"graphql-hooks-memcache": "^1.3.3", | ||
"graphql-hooks-ssr": "^1.1.5", | ||
"graphql-hooks-memcache": "^2.0.0", | ||
"graphql-hooks-ssr": "^2.0.0", | ||
"jest-fetch-mock": "^3.0.0", | ||
@@ -62,3 +62,3 @@ "react": "^16.12.0", | ||
"homepage": "https://github.com/nearform/graphql-hooks#readme", | ||
"gitHead": "cd4178b53ed20d220fa0e01ba498af6b86bfca35" | ||
"gitHead": "99518671cfdb8516386b550d167aef4443107976" | ||
} |
@@ -393,3 +393,3 @@ # graphql-hooks | ||
const client = new GraphQLClient({ | ||
url: 'http://localhost:8000/graphql' | ||
url: 'http://localhost:8000/graphql', | ||
subscriptionClient: new SubscriptionClient('ws://localhost:8000/graphql', { | ||
@@ -396,0 +396,0 @@ /* additional config options */ |
import React from 'react' | ||
import deepEqual from 'dequal' | ||
import { dequal } from 'dequal' | ||
import ClientContext from './ClientContext' | ||
@@ -61,3 +61,3 @@ | ||
if (!deepEqual(deps, ref.current)) { | ||
if (!dequal(deps, ref.current)) { | ||
ref.current = deps | ||
@@ -64,0 +64,0 @@ } |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
161965
2588
+ Addeddequal@2.0.3(transitive)
+ Addedextract-files@9.0.0(transitive)
- Removeddequal@1.0.1(transitive)
- Removedextract-files@8.1.0(transitive)
Updateddequal@^2.0.0
Updatedextract-files@^9.0.0