graphql-hooks
Advanced tools
Comparing version 3.6.1 to 4.0.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [4.0.0](https://github.com/nearform/graphql-hooks/compare/graphql-hooks@3.6.1...graphql-hooks@4.0.0) (2019-08-20) | ||
**Note:** Version bump only for package graphql-hooks | ||
## [3.6.1](https://github.com/nearform/graphql-hooks/compare/graphql-hooks@3.6.0...graphql-hooks@3.6.1) (2019-08-05) | ||
@@ -8,0 +16,0 @@ |
@@ -192,18 +192,19 @@ (function (global, factory) { | ||
console.groupEnd(); | ||
var error = result.error; | ||
if (result.fetchError) { | ||
if (error.fetchError) { | ||
console.groupCollapsed('FETCH ERROR:'); | ||
console.log(result.fetchError); | ||
console.log(error.fetchError); | ||
console.groupEnd(); | ||
} | ||
if (result.httpError) { | ||
if (error.httpError) { | ||
console.groupCollapsed('HTTP ERROR:'); | ||
console.log(result.httpError); | ||
console.log(error.httpError); | ||
console.groupEnd(); | ||
} | ||
if (result.graphQLErrors && result.graphQLErrors.length > 0) { | ||
if (error.graphQLErrors && error.graphQLErrors.length > 0) { | ||
console.groupCollapsed('GRAPHQL ERROR:'); | ||
result.graphQLErrors.forEach(function (err) { | ||
error.graphQLErrors.forEach(function (err) { | ||
return console.log(err); | ||
@@ -224,9 +225,12 @@ }); | ||
data = _ref2.data; | ||
var error = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError); | ||
return { | ||
error: error, | ||
fetchError: fetchError, | ||
httpError: httpError, | ||
graphQLErrors: graphQLErrors, | ||
var errorFound = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError); | ||
return !errorFound ? { | ||
data: data | ||
} : { | ||
data: data, | ||
error: { | ||
fetchError: fetchError, | ||
httpError: httpError, | ||
graphQLErrors: graphQLErrors | ||
} | ||
}; | ||
@@ -233,0 +237,0 @@ }; |
@@ -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(),r.fetchError&&(console.groupCollapsed("FETCH ERROR:"),console.log(r.fetchError),console.groupEnd()),r.httpError&&(console.groupCollapsed("HTTP ERROR:"),console.log(r.httpError),console.groupEnd()),r.graphQLErrors&&r.graphQLErrors.length>0&&(console.groupCollapsed("GRAPHQL ERROR:"),r.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;return{error:!!(n&&n.length>0||r||t),fetchError:r,httpError:t,graphQLErrors:n,data:e.data}},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?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})}); |
@@ -128,18 +128,19 @@ import React from 'react'; | ||
console.groupEnd(); | ||
var error = result.error; | ||
if (result.fetchError) { | ||
if (error.fetchError) { | ||
console.groupCollapsed('FETCH ERROR:'); | ||
console.log(result.fetchError); | ||
console.log(error.fetchError); | ||
console.groupEnd(); | ||
} | ||
if (result.httpError) { | ||
if (error.httpError) { | ||
console.groupCollapsed('HTTP ERROR:'); | ||
console.log(result.httpError); | ||
console.log(error.httpError); | ||
console.groupEnd(); | ||
} | ||
if (result.graphQLErrors && result.graphQLErrors.length > 0) { | ||
if (error.graphQLErrors && error.graphQLErrors.length > 0) { | ||
console.groupCollapsed('GRAPHQL ERROR:'); | ||
result.graphQLErrors.forEach(function (err) { | ||
error.graphQLErrors.forEach(function (err) { | ||
return console.log(err); | ||
@@ -160,9 +161,12 @@ }); | ||
data = _ref2.data; | ||
var error = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError); | ||
return { | ||
error: error, | ||
fetchError: fetchError, | ||
httpError: httpError, | ||
graphQLErrors: graphQLErrors, | ||
var errorFound = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError); | ||
return !errorFound ? { | ||
data: data | ||
} : { | ||
data: data, | ||
error: { | ||
fetchError: fetchError, | ||
httpError: httpError, | ||
graphQLErrors: graphQLErrors | ||
} | ||
}; | ||
@@ -169,0 +173,0 @@ }; |
@@ -99,5 +99,3 @@ import * as React from 'react' | ||
interface Result { | ||
data?: object | ||
error?: boolean | ||
interface APIError { | ||
fetchError?: Error | ||
@@ -108,2 +106,7 @@ httpError?: HttpError | ||
interface Result { | ||
data?: object | ||
error?: APIError | ||
} | ||
interface UseClientRequestOptions { | ||
@@ -127,7 +130,4 @@ useCache?: boolean | ||
cacheHit: boolean | ||
error: boolean | ||
data: ResponseData | ||
fetchError?: Error | ||
httpError?: HttpError | ||
graphQLErrors?: object[] | ||
error?: APIError | ||
} | ||
@@ -134,0 +134,0 @@ |
@@ -134,18 +134,19 @@ 'use strict'; | ||
console.groupEnd(); | ||
var error = result.error; | ||
if (result.fetchError) { | ||
if (error.fetchError) { | ||
console.groupCollapsed('FETCH ERROR:'); | ||
console.log(result.fetchError); | ||
console.log(error.fetchError); | ||
console.groupEnd(); | ||
} | ||
if (result.httpError) { | ||
if (error.httpError) { | ||
console.groupCollapsed('HTTP ERROR:'); | ||
console.log(result.httpError); | ||
console.log(error.httpError); | ||
console.groupEnd(); | ||
} | ||
if (result.graphQLErrors && result.graphQLErrors.length > 0) { | ||
if (error.graphQLErrors && error.graphQLErrors.length > 0) { | ||
console.groupCollapsed('GRAPHQL ERROR:'); | ||
result.graphQLErrors.forEach(function (err) { | ||
error.graphQLErrors.forEach(function (err) { | ||
return console.log(err); | ||
@@ -166,9 +167,12 @@ }); | ||
data = _ref2.data; | ||
var error = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError); | ||
return { | ||
error: error, | ||
fetchError: fetchError, | ||
httpError: httpError, | ||
graphQLErrors: graphQLErrors, | ||
var errorFound = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError); | ||
return !errorFound ? { | ||
data: data | ||
} : { | ||
data: data, | ||
error: { | ||
fetchError: fetchError, | ||
httpError: httpError, | ||
graphQLErrors: graphQLErrors | ||
} | ||
}; | ||
@@ -175,0 +179,0 @@ }; |
{ | ||
"name": "graphql-hooks", | ||
"version": "3.6.1", | ||
"version": "4.0.0", | ||
"description": "Graphql Hooks", | ||
@@ -56,3 +56,3 @@ "main": "lib/graphql-hooks.js", | ||
"homepage": "https://github.com/nearform/graphql-hooks#readme", | ||
"gitHead": "e8f7b4aa56cba0ae16c61b16a9bb71c3d44cd332" | ||
"gitHead": "e50586ceebd630fb2c187c3b38089cf688d0e9c8" | ||
} |
@@ -144,3 +144,3 @@ # graphql-hooks | ||
- `operation`: Object with `query`, `variables` and `operationName` | ||
- `result`: Object containing `error`, `data`, `fetchError`, `httpError` and `graphqlErrors` | ||
- `result`: Object containing `data` and `error` object that contains `fetchError`, `httpError` and `graphqlErrors` | ||
@@ -226,7 +226,6 @@ ### `client` methods | ||
```js | ||
const { loading, error, data, refetch, cacheHit, ...errors } = useQuery(QUERY) | ||
const { loading, error, data, refetch, cacheHit } = useQuery(QUERY) | ||
``` | ||
- `loading`: Boolean - `true` if the query is in flight | ||
- `error`: Boolean - `true` if `fetchError` or `httpError` or `graphQLErrors` has been set | ||
- `data`: Object - the result of your GraphQL query | ||
@@ -236,5 +235,6 @@ - `refetch(options)`: Function - useful when refetching the same query after a mutation; NOTE this presets `skipCache=true` & will bypass the `options.updateData` function that was passed into `useQuery`. You can pass a new `updateData` into `refetch` if necessary. | ||
- `cacheHit`: Boolean - `true` if the query result came from the cache, useful for debugging | ||
- `fetchError`: Object - Set if an error occurred during the `fetch` call | ||
- `httpError`: Object - Set if an error response was returned from the server | ||
- `graphQLErrors`: Array - Populated if any errors occurred whilst resolving the query | ||
- `error`: Object - Set if at least one of the following errors has occured and contains: | ||
* `fetchError`: Object - Set if an error occurred during the `fetch` call | ||
* `httpError`: Object - Set if an error response was returned from the server | ||
* `graphQLErrors`: Array - Populated if any errors occurred whilst resolving the query | ||
@@ -241,0 +241,0 @@ ## `useManualQuery` |
@@ -61,17 +61,19 @@ import { extractFiles } from 'extract-files' | ||
if (result.fetchError) { | ||
const error = result.error | ||
if (error.fetchError) { | ||
console.groupCollapsed('FETCH ERROR:') | ||
console.log(result.fetchError) | ||
console.log(error.fetchError) | ||
console.groupEnd() | ||
} | ||
if (result.httpError) { | ||
if (error.httpError) { | ||
console.groupCollapsed('HTTP ERROR:') | ||
console.log(result.httpError) | ||
console.log(error.httpError) | ||
console.groupEnd() | ||
} | ||
if (result.graphQLErrors && result.graphQLErrors.length > 0) { | ||
if (error.graphQLErrors && error.graphQLErrors.length > 0) { | ||
console.groupCollapsed('GRAPHQL ERROR:') | ||
result.graphQLErrors.forEach(err => console.log(err)) | ||
error.graphQLErrors.forEach(err => console.log(err)) | ||
console.groupEnd() | ||
@@ -84,3 +86,3 @@ } | ||
generateResult({ fetchError, httpError, graphQLErrors, data }) { | ||
const error = !!( | ||
const errorFound = !!( | ||
(graphQLErrors && graphQLErrors.length > 0) || | ||
@@ -90,10 +92,5 @@ fetchError || | ||
) | ||
return { | ||
error, | ||
fetchError, | ||
httpError, | ||
graphQLErrors, | ||
data | ||
} | ||
return !errorFound | ||
? { data } | ||
: { data, error: { fetchError, httpError, graphQLErrors } } | ||
} | ||
@@ -100,0 +97,0 @@ |
Sorry, the diff of this file is not supported yet
116440
2016