graphql-hooks
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -6,2 +6,14 @@ # Change Log | ||
## [4.0.2](https://github.com/nearform/graphql-hooks/compare/graphql-hooks@4.0.1...graphql-hooks@4.0.2) (2019-10-24) | ||
### Bug Fixes | ||
* publishing issues ([#389](https://github.com/nearform/graphql-hooks/issues/389)) ([7e1c4a2](https://github.com/nearform/graphql-hooks/commit/7e1c4a2ba8a6c08d09139733b2b897b81374fbac)) | ||
* Server-side rendering ([#382](https://github.com/nearform/graphql-hooks/issues/382)) ([7256bde](https://github.com/nearform/graphql-hooks/commit/7256bde4e52fc78479c887c7671eb7fb82cbd0d0)), closes [#371](https://github.com/nearform/graphql-hooks/issues/371) | ||
## [4.0.1](https://github.com/nearform/graphql-hooks/compare/graphql-hooks@4.0.0...graphql-hooks@4.0.1) (2019-10-04) | ||
@@ -8,0 +20,0 @@ |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = global || self, factory(global.GraphQLHooks = {}, global.React)); | ||
}(this, function (exports, React) { 'use strict'; | ||
}(this, (function (exports, React) { 'use strict'; | ||
@@ -397,3 +397,3 @@ React = React && React.hasOwnProperty('default') ? React['default'] : React; | ||
case actionTypes.CACHE_HIT: | ||
if (state.cacheHit) { | ||
if (state.cacheHit && !action.resetState) { | ||
// we can be sure this is the same cacheKey hit | ||
@@ -511,3 +511,4 @@ // because we dispatch RESET_STATE if it changes | ||
type: actionTypes.CACHE_HIT, | ||
result: cacheHit | ||
result: cacheHit, | ||
resetState: stringifiedCacheKey !== JSON.stringify(state.cacheKey) | ||
}); | ||
@@ -530,2 +531,9 @@ return Promise.resolve(cacheHit); | ||
actionResult.cacheKey = revisedCacheKey; | ||
if (client.ssrMode) { | ||
var cacheValue = { | ||
data: revisedOpts.updateData ? revisedOpts.updateData(state.data, actionResult.data) : actionResult.data | ||
}; | ||
client.saveCache(revisedCacheKey, cacheValue); | ||
} | ||
} | ||
@@ -577,3 +585,3 @@ | ||
// result may already be in the cache from previous SSR iterations | ||
if (!state.loading && !state.data && !state.error) { | ||
if (!state.data && !state.error) { | ||
var p = queryReq(); | ||
@@ -632,2 +640,2 @@ client.ssrPromises.push(p); | ||
})); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e=e||self).GraphQLHooks={},e.React)}(this,function(e,r){"use strict";function t(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function o(e){for(var r=1;arguments.length>r;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(o,!0).forEach(function(r){t(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(o).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}var a=(r=r&&r.hasOwnProperty("default")?r.default:r).createContext();a.displayName="ClientContext";var i=function(e){var r=e.name,t=e.type;this.uri=e.uri,this.name=r,this.type=t};var s=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.logErrors=void 0===e.logErrors||e.logErrors,this.onError=e.onError}var r=e.prototype;return r.setHeader=function(e,r){return this.headers[e]=r,this},r.setHeaders=function(e){return this.headers=e,this},r.removeHeader=function(e){return delete this.headers[e],this},r.logErrorResult=function(e){var r=e.result,t=e.operation;if(this.onError)return this.onError({result:r,operation:t});console.error("GraphQL Hooks Error"),console.groupCollapsed("---\x3e Full Error Details"),console.groupCollapsed("Operation:"),console.log(t),console.groupEnd();var n=r.error;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()},r.generateResult=function(e){var r=e.fetchError,t=e.httpError,n=e.graphQLErrors,o=e.data;return!!(n&&n.length>0||r||t)?{data:o,error:{fetchError:r,httpError:t,graphQLErrors:n}}:{data:o}},r.getCacheKey=function(e,r){return void 0===r&&(r={}),{operation:e,fetchOptions:o({},this.fetchOptions,{},r.fetchOptionsOverrides)}},r.getCache=function(e){var r=this.cache?this.cache.get(e):null;if(r)return r},r.saveCache=function(e,r){this.cache&&this.cache.set(e,r)},r.getFetchOptions=function(e,r){void 0===r&&(r={});var t=o({method:"POST",headers:o({},this.headers)},this.fetchOptions,{},r),n=function e(r,t){var n;void 0===t&&(t="");var o=new Map;function a(e,r){var t=o.get(r);t?t.push.apply(t,e):o.set(r,e)}if("undefined"!=typeof File&&r instanceof File||"undefined"!=typeof Blob&&r instanceof Blob||r instanceof i)n=null,a([t],r);else{var s=t?t+".":"";if("undefined"!=typeof FileList&&r instanceof FileList)n=Array.prototype.map.call(r,function(e,r){return a([""+s+r],e),null});else if(Array.isArray(r))n=r.map(function(r,t){var n=e(r,""+s+t);return n.files.forEach(a),n.clone});else if(r&&r.constructor===Object)for(var u in n={},r){var c=e(r[u],""+s+u);c.files.forEach(a),n[u]=c.clone}else n=r}return{clone:n,files:o}}(e),a=n.files,s=JSON.stringify(n.clone);if(a.size){var u=new FormData;u.append("operations",s);var c={},f=0;a.forEach(function(e){c[++f]=e}),u.append("map",JSON.stringify(c)),f=0,a.forEach(function(e,r){u.append(""+ ++f,r,r.name)}),t.body=u}else t.headers["Content-Type"]="application/json",t.body=s;return t},r.request=function(e,r){var t=this;return void 0===r&&(r={}),this.fetch(this.url,this.getFetchOptions(e,r.fetchOptionsOverrides)).then(function(e){return e.ok?e.json().then(function(e){return t.generateResult({graphQLErrors:e.errors,data:e.data})}):e.text().then(function(r){return t.generateResult({httpError:{status:e.status,statusText:e.statusText,body:r}})})}).catch(function(e){return t.generateResult({fetchError:e})}).then(function(r){return r.error&&t.logErrors&&t.logErrorResult({result:r,operation:e}),r})},e}();var u={RESET_STATE:"RESET_STATE",LOADING:"LOADING",CACHE_HIT:"CACHE_HIT",REQUEST_RESULT:"REQUEST_RESULT"};function c(e,r){switch(r.type){case u.RESET_STATE:return r.initialState;case u.LOADING:return e.loading?e:o({},e,{loading:!0});case u.CACHE_HIT:return e.cacheHit?e:o({},r.result,{cacheHit:!0,loading:!1});case u.REQUEST_RESULT:return o({},r.result,{data:e.data&&r.result.data&&r.updateData?r.updateData(e.data,r.result.data):r.result.data,cacheHit:!1,loading:!1});default:return e}}function f(e,t){var n=r.useRef();return function e(r,t){var n,o;if(r===t)return!0;if(r&&t&&(n=r.constructor)===t.constructor){if(n===Date)return r.getTime()===t.getTime();if(n===RegExp)return""+r==""+t;if(n===Array&&(o=r.length)===t.length){for(;o--&&e(r[o],t[o]););return-1===o}if(n===Object){if(Object.keys(r).length!==Object.keys(t).length)return!1;for(o in r)if(!(o in t&&e(r[o],t[o])))return!1;return!0}}return r!=r&&t!=t}(t,n.current)||(n.current=t),r.useCallback(e,n.current)}function l(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),i=r.useRef(!0),s=r.useRef(null),l={query:e,variables:t.variables,operationName:t.operationName},h=n.getCacheKey(l,t),p=t.isMutation||t.isManual,d=t.skipCache||!n.cache?null:n.cache.get(h),E=o({},d,{cacheHit:!!d,loading:!p&&!d}),g=r.useReducer(c,E),y=g[0],v=g[1],C=JSON.stringify(h);r.useEffect(function(){t.updateData||v({type:u.RESET_STATE,initialState:E})},[C]),r.useEffect(function(){return i.current=!0,function(){i.current=!1}},[]);var O=f(function(e){if(!i.current)return Promise.resolve();var r=o({},t,{},e),a=o({},l,{variables:r.variables,operationName:r.operationName}),c=n.getCacheKey(a,r);s.current=c;var f=r.skipCache?null:n.getCache(c);return f?(v({type:u.CACHE_HIT,result:f}),Promise.resolve(f)):(v({type:u.LOADING}),n.request(a,r).then(function(e){if(r.updateData&&"function"!=typeof r.updateData)throw Error("options.updateData must be a function");var t=o({},e);return r.useCache&&(t.useCache=!0,t.cacheKey=c),i.current&&c===s.current&&v({type:u.REQUEST_RESULT,updateData:r.updateData,result:t}),e}))},[n,t,l]);return r.useEffect(function(){y.useCache&&n.saveCache(y.cacheKey,y)},[n,y]),[O,y]}var h={useCache:!0};e.ClientContext=a,e.GraphQLClient=s,e.useClientRequest=l,e.useManualQuery=function(e,r){return l(e,o({useCache:!0,isManual:!0},r))},e.useMutation=function(e,r){return l(e,o({isMutation:!0},r))},e.useQuery=function(e,t){void 0===t&&(t={});var n=o({},h,{},t),i=r.useContext(a),s=r.useState(!1),u=s[0],c=s[1],f=l(e,n),p=f[0],d=f[1];if(i.ssrMode&&!1!==t.ssr&&!u){if(!d.loading&&!d.data&&!d.error){var E=p();i.ssrPromises.push(E)}c(!0)}var g=JSON.stringify(n);return r.useEffect(function(){p()},[e,g]),o({},d,{refetch:r.useCallback(function(e){return void 0===e&&(e={}),p(o({skipCache:!0,updateData:function(e,r){return r}},e))},[p])})},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e=e||self).GraphQLHooks={},e.React)}(this,(function(e,r){"use strict";function t(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function o(e){for(var r=1;arguments.length>r;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(o,!0).forEach((function(r){t(e,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(o).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))}))}return e}var a=(r=r&&r.hasOwnProperty("default")?r.default:r).createContext();a.displayName="ClientContext";var i=function(e){var r=e.name,t=e.type;this.uri=e.uri,this.name=r,this.type=t};var s=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.logErrors=void 0===e.logErrors||e.logErrors,this.onError=e.onError}var r=e.prototype;return r.setHeader=function(e,r){return this.headers[e]=r,this},r.setHeaders=function(e){return this.headers=e,this},r.removeHeader=function(e){return delete this.headers[e],this},r.logErrorResult=function(e){var r=e.result,t=e.operation;if(this.onError)return this.onError({result:r,operation:t});console.error("GraphQL Hooks Error"),console.groupCollapsed("---\x3e Full Error Details"),console.groupCollapsed("Operation:"),console.log(t),console.groupEnd();var n=r.error;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()},r.generateResult=function(e){var r=e.fetchError,t=e.httpError,n=e.graphQLErrors,o=e.data;return!!(n&&n.length>0||r||t)?{data:o,error:{fetchError:r,httpError:t,graphQLErrors:n}}:{data:o}},r.getCacheKey=function(e,r){return void 0===r&&(r={}),{operation:e,fetchOptions:o({},this.fetchOptions,{},r.fetchOptionsOverrides)}},r.getCache=function(e){var r=this.cache?this.cache.get(e):null;if(r)return r},r.saveCache=function(e,r){this.cache&&this.cache.set(e,r)},r.getFetchOptions=function(e,r){void 0===r&&(r={});var t=o({method:"POST",headers:o({},this.headers)},this.fetchOptions,{},r),n=function e(r,t){var n;void 0===t&&(t="");var o=new Map;function a(e,r){var t=o.get(r);t?t.push.apply(t,e):o.set(r,e)}if("undefined"!=typeof File&&r instanceof File||"undefined"!=typeof Blob&&r instanceof Blob||r instanceof i)n=null,a([t],r);else{var s=t?t+".":"";if("undefined"!=typeof FileList&&r instanceof FileList)n=Array.prototype.map.call(r,(function(e,r){return a([""+s+r],e),null}));else if(Array.isArray(r))n=r.map((function(r,t){var n=e(r,""+s+t);return n.files.forEach(a),n.clone}));else if(r&&r.constructor===Object)for(var u in n={},r){var c=e(r[u],""+s+u);c.files.forEach(a),n[u]=c.clone}else n=r}return{clone:n,files:o}}(e),a=n.files,s=JSON.stringify(n.clone);if(a.size){var u=new FormData;u.append("operations",s);var c={},f=0;a.forEach((function(e){c[++f]=e})),u.append("map",JSON.stringify(c)),f=0,a.forEach((function(e,r){u.append(""+ ++f,r,r.name)})),t.body=u}else t.headers["Content-Type"]="application/json",t.body=s;return t},r.request=function(e,r){var t=this;return void 0===r&&(r={}),this.fetch(this.url,this.getFetchOptions(e,r.fetchOptionsOverrides)).then((function(e){return e.ok?e.json().then((function(e){return t.generateResult({graphQLErrors:e.errors,data:e.data})})):e.text().then((function(r){return t.generateResult({httpError:{status:e.status,statusText:e.statusText,body:r}})}))})).catch((function(e){return t.generateResult({fetchError:e})})).then((function(r){return r.error&&t.logErrors&&t.logErrorResult({result:r,operation:e}),r}))},e}();var u={RESET_STATE:"RESET_STATE",LOADING:"LOADING",CACHE_HIT:"CACHE_HIT",REQUEST_RESULT:"REQUEST_RESULT"};function c(e,r){switch(r.type){case u.RESET_STATE:return r.initialState;case u.LOADING:return e.loading?e:o({},e,{loading:!0});case u.CACHE_HIT:return e.cacheHit&&!r.resetState?e:o({},r.result,{cacheHit:!0,loading:!1});case u.REQUEST_RESULT:return o({},r.result,{data:e.data&&r.result.data&&r.updateData?r.updateData(e.data,r.result.data):r.result.data,cacheHit:!1,loading:!1});default:return e}}function f(e,t){var n=r.useRef();return function e(r,t){var n,o;if(r===t)return!0;if(r&&t&&(n=r.constructor)===t.constructor){if(n===Date)return r.getTime()===t.getTime();if(n===RegExp)return""+r==""+t;if(n===Array&&(o=r.length)===t.length){for(;o--&&e(r[o],t[o]););return-1===o}if(n===Object){if(Object.keys(r).length!==Object.keys(t).length)return!1;for(o in r)if(!(o in t&&e(r[o],t[o])))return!1;return!0}}return r!=r&&t!=t}(t,n.current)||(n.current=t),r.useCallback(e,n.current)}function l(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),i=r.useRef(!0),s=r.useRef(null),l={query:e,variables:t.variables,operationName:t.operationName},h=n.getCacheKey(l,t),p=t.isMutation||t.isManual,d=t.skipCache||!n.cache?null:n.cache.get(h),E=o({},d,{cacheHit:!!d,loading:!p&&!d}),g=r.useReducer(c,E),y=g[0],v=g[1],C=JSON.stringify(h);r.useEffect((function(){t.updateData||v({type:u.RESET_STATE,initialState:E})}),[C]),r.useEffect((function(){return i.current=!0,function(){i.current=!1}}),[]);var O=f((function(e){if(!i.current)return Promise.resolve();var r=o({},t,{},e),a=o({},l,{variables:r.variables,operationName:r.operationName}),c=n.getCacheKey(a,r);s.current=c;var f=r.skipCache?null:n.getCache(c);return f?(v({type:u.CACHE_HIT,result:f,resetState:C!==JSON.stringify(y.cacheKey)}),Promise.resolve(f)):(v({type:u.LOADING}),n.request(a,r).then((function(e){if(r.updateData&&"function"!=typeof r.updateData)throw Error("options.updateData must be a function");var t=o({},e);if(r.useCache&&(t.useCache=!0,t.cacheKey=c,n.ssrMode)){var a={data:r.updateData?r.updateData(y.data,t.data):t.data};n.saveCache(c,a)}return i.current&&c===s.current&&v({type:u.REQUEST_RESULT,updateData:r.updateData,result:t}),e})))}),[n,t,l]);return r.useEffect((function(){y.useCache&&n.saveCache(y.cacheKey,y)}),[n,y]),[O,y]}var h={useCache:!0};e.ClientContext=a,e.GraphQLClient=s,e.useClientRequest=l,e.useManualQuery=function(e,r){return l(e,o({useCache:!0,isManual:!0},r))},e.useMutation=function(e,r){return l(e,o({isMutation:!0},r))},e.useQuery=function(e,t){void 0===t&&(t={});var n=o({},h,{},t),i=r.useContext(a),s=r.useState(!1),u=s[0],c=s[1],f=l(e,n),p=f[0],d=f[1];if(i.ssrMode&&!1!==t.ssr&&!u){if(!d.data&&!d.error){var E=p();i.ssrPromises.push(E)}c(!0)}var g=JSON.stringify(n);return r.useEffect((function(){p()}),[e,g]),o({},d,{refetch:r.useCallback((function(e){return void 0===e&&(e={}),p(o({skipCache:!0,updateData:function(e,r){return r}},e))}),[p])})},Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -313,3 +313,3 @@ import React from 'react'; | ||
case actionTypes.CACHE_HIT: | ||
if (state.cacheHit) { | ||
if (state.cacheHit && !action.resetState) { | ||
// we can be sure this is the same cacheKey hit | ||
@@ -427,3 +427,4 @@ // because we dispatch RESET_STATE if it changes | ||
type: actionTypes.CACHE_HIT, | ||
result: cacheHit | ||
result: cacheHit, | ||
resetState: stringifiedCacheKey !== JSON.stringify(state.cacheKey) | ||
}); | ||
@@ -446,2 +447,9 @@ return Promise.resolve(cacheHit); | ||
actionResult.cacheKey = revisedCacheKey; | ||
if (client.ssrMode) { | ||
var cacheValue = { | ||
data: revisedOpts.updateData ? revisedOpts.updateData(state.data, actionResult.data) : actionResult.data | ||
}; | ||
client.saveCache(revisedCacheKey, cacheValue); | ||
} | ||
} | ||
@@ -493,3 +501,3 @@ | ||
// result may already be in the cache from previous SSR iterations | ||
if (!state.loading && !state.data && !state.error) { | ||
if (!state.data && !state.error) { | ||
var p = queryReq(); | ||
@@ -496,0 +504,0 @@ client.ssrPromises.push(p); |
@@ -319,3 +319,3 @@ 'use strict'; | ||
case actionTypes.CACHE_HIT: | ||
if (state.cacheHit) { | ||
if (state.cacheHit && !action.resetState) { | ||
// we can be sure this is the same cacheKey hit | ||
@@ -433,3 +433,4 @@ // because we dispatch RESET_STATE if it changes | ||
type: actionTypes.CACHE_HIT, | ||
result: cacheHit | ||
result: cacheHit, | ||
resetState: stringifiedCacheKey !== JSON.stringify(state.cacheKey) | ||
}); | ||
@@ -452,2 +453,9 @@ return Promise.resolve(cacheHit); | ||
actionResult.cacheKey = revisedCacheKey; | ||
if (client.ssrMode) { | ||
var cacheValue = { | ||
data: revisedOpts.updateData ? revisedOpts.updateData(state.data, actionResult.data) : actionResult.data | ||
}; | ||
client.saveCache(revisedCacheKey, cacheValue); | ||
} | ||
} | ||
@@ -499,3 +507,3 @@ | ||
// result may already be in the cache from previous SSR iterations | ||
if (!state.loading && !state.data && !state.error) { | ||
if (!state.data && !state.error) { | ||
var p = queryReq(); | ||
@@ -502,0 +510,0 @@ client.ssrPromises.push(p); |
{ | ||
"name": "graphql-hooks", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Graphql Hooks", | ||
@@ -10,3 +10,4 @@ "main": "lib/graphql-hooks.js", | ||
"scripts": { | ||
"build": "../../node_modules/.bin/rollup -c", | ||
"clean": "rm -rf ./dist ./es ./lib", | ||
"build": "rollup -c", | ||
"prepublishOnly": "npm run build && cp ../../README.md . && cp ../../LICENSE ." | ||
@@ -44,6 +45,9 @@ }, | ||
"formdata-node": "^1.6.0", | ||
"graphql-hooks-memcache": "^1.2.4", | ||
"graphql-hooks-ssr": "^1.1.4", | ||
"jest-fetch-mock": "^2.1.2", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-test-renderer": "^16.8.6" | ||
"react-test-renderer": "^16.8.6", | ||
"rollup": "^1.25.2" | ||
}, | ||
@@ -58,3 +62,3 @@ "repository": { | ||
"homepage": "https://github.com/nearform/graphql-hooks#readme", | ||
"gitHead": "634027982303907e15056302ffb7ecd3b683bc73" | ||
"gitHead": "69dd94f0c477548ebadc9c0a586aec42f941404b" | ||
} |
@@ -16,3 +16,3 @@ # graphql-hooks | ||
- 🥇 First-class hooks API | ||
- ⚖️ _Tiny_ bundle: only 5.3kB (1.9 gzipped) | ||
- ⚖️ _Tiny_ bundle: only 7.6kB (2.8 gzipped) | ||
- 📄 Full SSR support: see [graphql-hooks-ssr](packages/graphql-hooks-ssr) | ||
@@ -758,5 +758,1 @@ - 🔌 Plugin Caching: see [graphql-hooks-memcache](packages/graphql-hooks-memcache) | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! | ||
[](http://browserstack.com/) | ||
We use BrowserStack to support as many browsers and devices as possible |
@@ -25,3 +25,3 @@ import React from 'react' | ||
case actionTypes.CACHE_HIT: | ||
if (state.cacheHit) { | ||
if (state.cacheHit && !action.resetState) { | ||
// we can be sure this is the same cacheKey hit | ||
@@ -143,3 +143,4 @@ // because we dispatch RESET_STATE if it changes | ||
type: actionTypes.CACHE_HIT, | ||
result: cacheHit | ||
result: cacheHit, | ||
resetState: stringifiedCacheKey !== JSON.stringify(state.cacheKey) | ||
}) | ||
@@ -163,2 +164,11 @@ | ||
actionResult.cacheKey = revisedCacheKey | ||
if (client.ssrMode) { | ||
const cacheValue = { | ||
data: revisedOpts.updateData | ||
? revisedOpts.updateData(state.data, actionResult.data) | ||
: actionResult.data | ||
} | ||
client.saveCache(revisedCacheKey, cacheValue) | ||
} | ||
} | ||
@@ -165,0 +175,0 @@ |
@@ -18,3 +18,3 @@ import React from 'react' | ||
// result may already be in the cache from previous SSR iterations | ||
if (!state.loading && !state.data && !state.error) { | ||
if (!state.data && !state.error) { | ||
const p = queryReq() | ||
@@ -21,0 +21,0 @@ client.ssrPromises.push(p) |
Sorry, the diff of this file is not supported yet
120537
2048
10
757