New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-hooks

Package Overview
Dependencies
Maintainers
9
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-hooks - npm Package Compare versions

Comparing version 6.2.3 to 6.3.0

45

dist/graphql-hooks.js

@@ -686,3 +686,8 @@ (function (global, factory) {

}
return { data: result };
const { data, errors } = collectErrorsFromObject(result);
if (errors.length > 0) {
return { data, error: new LocalGraphQLError({ graphQLErrors: errors }) };
} else {
return { data };
}
});

@@ -696,2 +701,40 @@ }

}
function isObject(o) {
return o === Object(o);
}
function collectErrorsFromObject(objectIn) {
const data = {};
const errors = [];
for (const [key, value] of Object.entries(objectIn)) {
const child = collectErrorsFromChild(value);
data[key] = child.data;
if (child.errors != null) {
errors.push(...child.errors);
}
}
return { data, errors };
}
function collectErrorsFromArray(arrayIn) {
const data = Array(arrayIn.length);
const errors = [];
for (const [idx, entry] of arrayIn.entries()) {
const child = collectErrorsFromChild(entry);
data[idx] = child.data;
if (child.errors != null) {
errors.push(...child.errors);
}
}
return { data, errors };
}
function collectErrorsFromChild(entry) {
if (entry instanceof Error) {
return { data: null, errors: [entry] };
} else if (Array.isArray(entry)) {
return collectErrorsFromArray(entry);
} else if (isObject(entry)) {
return collectErrorsFromObject(entry);
} else {
return { data: entry, errors: null };
}
}

@@ -698,0 +741,0 @@ var has = Object.prototype.hasOwnProperty;

2

dist/graphql-hooks.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("events")):"function"==typeof define&&define.amd?define(["exports","react","events"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GraphQLHooks={},e.React,e.EventEmitter)}(this,(function(e,t,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(t),i=o(r);const s=n.default.createContext(null);s.displayName="ClientContext";var a=class{constructor({uri:e,name:t,type:r}){this.uri=e,this.name=t,this.type=r}},u=function(e){return"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof a},c=u,l=u,f=function(e,t="",r=l){const o=new Map,n=new Map;return{clone:function e(t,i,s){let a=t;if(r(t)){a=null;const e=o.get(t);e?e.push(i):o.set(t,[i])}else{const r=Array.isArray(t)||"undefined"!=typeof FileList&&t instanceof FileList;if(r||t&&t.constructor===Object){const o=n.has(t);if(o?a=n.get(t):(a=r?[]:{},n.set(t,a)),!s.has(t)){const n=i?i+".":"",u=new Set(s).add(t);if(r){let r=0;for(const i of t){const t=e(i,n+r++,u);o||a.push(t)}}else for(const r in t){const i=e(t[r],n+r,u);o||(a[r]=i)}}}}return a}(e,t,new Set),files:o}};const h=e=>c(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe||null!==e&&"object"==typeof e&&"function"==typeof e.stream;function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=Array(t);t>r;r++)o[r]=e[r];return o}function d(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return p(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?p(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return e.length>o?{done:!1,value:e[o++]}:{done:!0}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var y=function(){function e(e){var t=this;0===e.length&&e.push((function(e,t){return t()}));for(var r,o=function(){var e,o=r.value;if("function"!=typeof o)throw Error("GraphQLClient Middleware: middleware has to be of type `function`");t.run=(e=t.run,function(r,n){e(r,(function(){o.call(t,r,n.bind.call(n,null,r))}))})},n=d(e);!(r=n()).done;)o()}return e.prototype.run=function(e,t){t.apply(this,e)},e}();var b=(e=>(e.DATA_INVALIDATED="DATA_INVALIDATED",e.DATA_UPDATED="DATA_UPDATED",e))(b||{}),E=Object.defineProperty,m=Object.defineProperties,g=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,w=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,T=(e,t)=>{for(var r in t||(t={}))O.call(t,r)&&w(e,r,t[r]);if(v)for(var r of v(t))C.call(t,r)&&w(e,r,t[r]);return e};class A{constructor(e){if(!e)throw Error("GraphQLClient: config is required as first parameter");this.fullWsTransport=e.fullWsTransport,this.subscriptionClient="function"==typeof e.subscriptionClient?e.subscriptionClient():e.subscriptionClient,this.verifyConfig(e),this.cache=e.cache,this.headers=e.headers||{},this.ssrMode=e.ssrMode,this.ssrPromises=[],this.url=e.url,this.fetch=e.fetch||("undefined"!=typeof fetch&&fetch?fetch.bind(void 0):void 0),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.middleware=new y(e.middleware||[]),this.mutationsEmitter=new i.default}verifyConfig(e){if(!e.url){if(!this.fullWsTransport)throw Error("GraphQLClient: config.url is required");if(!this.subscriptionClient)throw Error("GraphQLClient: subscriptionClient is required")}if(e.fetch&&"function"!=typeof e.fetch)throw Error("GraphQLClient: config.fetch must be a function");if(("undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement||e.ssrMode)&&!e.fetch&&"function"!=typeof 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")}setHeader(e,t){return this.headers[e]=t,this}setHeaders(e){return this.headers=e,this}removeHeader(e){return delete this.headers[e],this}logErrorResult({result:e,operation:t}){console.error("GraphQL Hooks Error"),console.groupCollapsed("---\x3e Full Error Details"),console.groupCollapsed("Operation:"),console.log(t),console.groupEnd();const r=e.error;r&&(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((e=>console.log(e))),console.groupEnd())),console.groupEnd()}generateResult({fetchError:e,httpError:t,graphQLErrors:r,data:o}){return!!(r&&r.length>0||e||t)?{data:o,error:{fetchError:e,httpError:t,graphQLErrors:r}}:{data:o}}getCacheKey(e,t={}){return{operation:e,fetchOptions:T(T({},this.fetchOptions),t.fetchOptionsOverrides)}}getCache(e){const t=this.cache?this.cache.get(e):null;if(t)return t}saveCache(e,t){this.cache&&this.cache.set(e,t)}removeCache(e){var t;null==(t=this.cache)||t.delete(e)}getFetchOptions(e,t={}){const r=T(T({method:"POST",headers:T({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;const{clone:o,files:n}=f(e,"",h),i=JSON.stringify(o);if(n.size){if(!this.FormData)throw Error("GraphQLClient: FormData must be polyfilled or passed in new GraphQLClient({ FormData })");const e=new this.FormData;e.append("operations",i);const t={};let o=0;n.forEach((e=>{t[++o]=e})),e.append("map",JSON.stringify(t)),o=0,n.forEach(((t,r)=>{e.append(""+ ++o,r,r.name)})),r.body=e}else r.headers["Content-Type"]="application/json",r.body=i;return r}request(e,t){const r=[],o=e=>r.push(e);return new Promise(((n,i)=>this.middleware.run({operation:e,client:this,addResponseHook:o,resolve:n,reject:i},(({operation:e})=>{const o=e=>{return r.length>0?(t=r,e=>t.reduce(((e,t)=>e.then(t)),Promise.resolve(e)))(e):e;var t};return this.fullWsTransport?this.requestViaWS(e).then(o).then(n).catch(i):this.url?this.requestViaHttp(e,t).then(o).then(n).catch(i):void i(Error("GraphQLClient: config.url is required"))}))))}requestViaHttp(e,t={}){let r=this.url;const o=this.getFetchOptions(e,t.fetchOptionsOverrides);if("GET"===o.method){r=r+"?"+Object.entries(e).filter((([,e])=>!!e)).map((([e,t])=>("variables"!==e&&"extensions"!==e||(t=JSON.stringify(t)),`${e}=${encodeURIComponent(t)}`))).join("&")}return this.fetch(r,o).then((e=>e.ok?e.json().then((({errors:r,data:o})=>this.generateResult({graphQLErrors:r,data:"function"==typeof t.responseReducer&&t.responseReducer(o,e)||o}))):e.text().then((t=>{const{status:r,statusText:o}=e;return this.generateResult({httpError:{status:r,statusText:o,body:t}})})))).catch((e=>this.generateResult({fetchError:e}))).then((t=>(t.error&&(this.logErrors&&this.logErrorResult({result:t,operation:e}),this.onError&&this.onError({result:t,operation:e})),t)))}requestViaWS(e){return new Promise(((t,r)=>{let o;try{const n=this.createSubscription(e).subscribe({next:e=>{o=e},error:r,complete:()=>{n.unsubscribe(),t(o)}})}catch(e){r(e)}}))}createSubscription(e){if(!this.subscriptionClient)throw Error("No SubscriptionClient! Please set in the constructor.");return"function"==typeof this.subscriptionClient.subscribe?{subscribe:t=>({unsubscribe:this.subscriptionClient.subscribe(e,t)})}:this.subscriptionClient.request(e)}invalidateQuery(e){const t="string"==typeof e?{query:e}:e,r=this.getCacheKey(t);this.cache&&r&&(this.removeCache(r),this.request(t).then((e=>{this.mutationsEmitter.emit(b.DATA_INVALIDATED,e)})).catch((e=>console.error(e))))}setQueryData(e,t){const r=this.getCacheKey("string"==typeof e?{query:e}:e);if(this.cache&&r){const e=this.cache.get(r),i=(o=T({},e),n={data:t(e.data||null)},m(o,g(n)));this.saveCache(r,i),this.mutationsEmitter.emit(b.DATA_UPDATED,i)}var o,n}}class D{constructor(e){this.fetchError=e.fetchError,this.httpError=e.httpError,this.graphQLErrors=e.graphQLErrors}}var S=Object.defineProperty,L=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,P=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var R=Object.prototype.hasOwnProperty;function q(e,t,r){for(r of e.keys())if(I(r,t))return r}function I(e,t){var r,o,n;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((o=e.length)===t.length)for(;o--&&I(e[o],t[o]););return-1===o}if(r===Set){if(e.size!==t.size)return!1;for(o of e){if((n=o)&&"object"==typeof n&&!(n=q(t,n)))return!1;if(!t.has(n))return!1}return!0}if(r===Map){if(e.size!==t.size)return!1;for(o of e){if((n=o[0])&&"object"==typeof n&&!(n=q(t,n)))return!1;if(!I(o[1],t.get(n)))return!1}return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((o=e.byteLength)===t.byteLength)for(;o--&&e.getInt8(o)===t.getInt8(o););return-1===o}if(ArrayBuffer.isView(e)){if((o=e.byteLength)===t.byteLength)for(;o--&&e[o]===t[o];);return-1===o}if(!r||"object"==typeof e){for(r in o=0,e){if(R.call(e,r)&&++o&&!R.call(t,r))return!1;if(!(r in t)||!I(e[r],t[r]))return!1}return Object.keys(t).length===o}}return e!=e&&t!=t}var M=Object.defineProperty,G=Object.defineProperties,_=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,k=(e,t,r)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,F=(e,t)=>{for(var r in t||(t={}))x.call(t,r)&&k(e,r,t[r]);if(H)for(var r of H(t))N.call(t,r)&&k(e,r,t[r]);return e},U=(e,t)=>G(e,_(t));const V={RESET_STATE:"RESET_STATE",LOADING:"LOADING",CACHE_HIT:"CACHE_HIT",REQUEST_RESULT:"REQUEST_RESULT"};function K(e,t){switch(t.type){case V.RESET_STATE:return e.loading?e:t.initialState;case V.LOADING:return e.error?U(F({},t.initialState),{data:e.data,loading:!0}):e.loading?e:U(F({},e),{loading:!0});case V.CACHE_HIT:return e.cacheHit&&!t.resetState?e:U(F({},t.result),{cacheHit:!0,loading:!1});case V.REQUEST_RESULT:return U(F({},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 J(e,t={}){if("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.");const r=n.default.useContext(s),o=t.client||r;if(null==o)throw Error("A client must be provided in order to use the useClientRequest hook.");const i=n.default.useRef(!0),a=n.default.useRef(null),u={query:e,variables:t.variables,operationName:t.operationName,persisted:t.persisted};(t.persisted||o.useGETForQueries&&!t.isMutation)&&(t.fetchOptionsOverrides=U(F({},t.fetchOptionsOverrides),{method:"GET"}));const c=o.getCacheKey(u,t),l=t.isMutation||t.isManual||t.skip,f=!t.skipCache&&o.cache&&c?o.cache.get(c):null,h=U(F({},f),{cacheHit:!!f,loading:!l&&!f}),[p,d]=n.default.useReducer(K,h),y=JSON.stringify(c);n.default.useEffect((()=>{t.updateData||d({type:V.RESET_STATE,initialState:h})}),[y]),n.default.useEffect((()=>(i.current=!0,()=>{i.current=!1})),[]);const E=function(e,t){const r=n.default.useRef();return I(t,r.current)||(r.current=t),n.default.useCallback(e,r.current)}((r=>{const n=F(F({},t),r),s=U(F({},u),{variables:n.variables,operationName:n.operationName});if(!i.current)return Promise.resolve({error:{fetchError:Error("fetchData should not be called after hook unmounted")},loading:!1,cacheHit:!1});const c=o.getCacheKey(s,n);a.current=c;const l=n.skipCache?null:o.getCache(c);return l?(d({type:V.CACHE_HIT,result:l,resetState:y!==JSON.stringify(p.cacheKey)}),Promise.resolve(l)):(d({type:V.LOADING,initialState:h}),o.request(s,n).then((r=>{if(n.updateData&&"function"!=typeof n.updateData)throw Error("options.updateData must be a function");const u=F({},r);if(n.useCache&&(u.useCache=!0,u.cacheKey=c,o.ssrMode)){const e={error:u.error,data:n.updateData?n.updateData(p.data,u.data):u.data};o.saveCache(c,e)}if(i.current&&c===a.current&&d({type:V.REQUEST_RESULT,updateData:n.updateData,result:u}),t.isMutation&&o.mutationsEmitter.emit(e,U(F({},s),{mutation:e,result:u})),!(null==r?void 0:r.error)&&n.onSuccess){if("function"!=typeof n.onSuccess)throw Error("options.onSuccess must be a function");n.onSuccess(r,s.variables)}return r})))}),[o,t,u]);n.default.useEffect((()=>{p.useCache&&!o.ssrMode&&o.saveCache(p.cacheKey,p)}),[o,p]);return n.default.useEffect((()=>{const e=(e,t)=>{d({type:t,result:e})},t=t=>e(t,V.REQUEST_RESULT),r=t=>e(t,V.CACHE_HIT),n=o.mutationsEmitter;return n.on(b.DATA_INVALIDATED,t),n.on(b.DATA_UPDATED,r),()=>{n&&(n.removeListener(b.DATA_INVALIDATED,t),n.removeListener(b.DATA_UPDATED,r))}}),[]),[E,p,(e={})=>d({type:V.RESET_STATE,initialState:F(F({},h),e)})]}var W=Object.defineProperty,z=Object.defineProperties,B=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,Z=(e,t,r)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ee=(e,t)=>{for(var r in t||(t={}))Y.call(t,r)&&Z(e,r,t[r]);if($)for(var r of $(t))X.call(t,r)&&Z(e,r,t[r]);return e},te=(e,t)=>z(e,B(t));const re={useCache:!0,skip:!1,throwErrors:!1};var oe=Object.defineProperty,ne=Object.getOwnPropertySymbols,ie=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,ae=(e,t,r)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ue=Object.defineProperty,ce=Object.getOwnPropertySymbols,le=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable,he=(e,t,r)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;e.ClientContext=s,e.GraphQLClient=A,e.LocalGraphQLClient=class extends A{constructor(e){if(super(((e,t)=>{for(var r in t||(t={}))j.call(t,r)&&P(e,r,t[r]);if(L)for(var r of L(t))Q.call(t,r)&&P(e,r,t[r]);return e})({url:""},e)),this.localQueries=e.localQueries,this.requestDelayMs=e.requestDelayMs||0,!this.localQueries)throw Error("LocalGraphQLClient: `localQueries` object required in the constructor options")}verifyConfig(){}request(e){if(!this.localQueries[e.query])throw Error("LocalGraphQLClient: no query match for: "+e.query);return(t=this.requestDelayMs,new Promise((e=>{setTimeout(e,t)}))).then((()=>Promise.resolve(this.localQueries[e.query](e.variables,e.operationName)))).then((e=>e instanceof D?{error:e}:{data:e}));var t}},e.LocalGraphQLError=D,e.useClientRequest=J,e.useManualQuery=(e,t={})=>J(e,((e,t)=>{for(var r in t||(t={}))le.call(t,r)&&he(e,r,t[r]);if(ce)for(var r of ce(t))fe.call(t,r)&&he(e,r,t[r]);return e})({useCache:!0,isManual:!0},t)),e.useMutation=(e,t={})=>J(e,((e,t)=>{for(var r in t||(t={}))ie.call(t,r)&&ae(e,r,t[r]);if(ne)for(var r of ne(t))se.call(t,r)&&ae(e,r,t[r]);return e})({isMutation:!0},t)),e.useQuery=function(e,t={}){const r=ee(ee({},re),t),o=n.default.useContext(s),i=t.client||o,[a,u]=n.default.useState(!1),[c,l]=J(e,r);if(!i)throw Error("useQuery() requires a client to be passed in the options or as a context value");if(i.ssrMode&&!1!==t.ssr&&!a&&!t.skipCache&&!t.skip){if(!l.data&&!l.error){const e=c();i.ssrPromises.push(e)}u(!0)}const f=JSON.stringify(r);n.default.useEffect((()=>{r.skip||c()}),[e,f]),n.default.useEffect((()=>{if(l.error&&r.throwErrors)throw l.error}),[l.error,r.throwErrors]);const h=n.default.useCallback(((e={})=>c(ee({skipCache:!0,updateData:(e,t)=>t},e))),[c]);return n.default.useEffect((function(){const e=(o={},(Array.isArray(r=t.refetchAfterMutations)?r:[r]).forEach((function(e){if(null!=e){var t=typeof e;if("string"===t)o[e]={};else if("object"===t){var r=e.refetchOnMutationError;o[e.mutation]={filter:e.filter,refetchOnMutationError:void 0===r||r}}}})),o);var r,o;const n=Object.keys(e),s=({mutation:t,variables:r,result:o})=>{const{filter:n,refetchOnMutationError:i}=e[t];(!n||r&&n(r))&&(i||!o.error)&&h()};return n.forEach((e=>{i.mutationsEmitter.on(e,s)})),()=>{n.forEach((e=>{i.mutationsEmitter.removeListener(e,s)}))}}),[t.refetchAfterMutations,h,i.mutationsEmitter]),te(ee({},l),{refetch:h})},e.useQueryClient=function(){return t.useContext(s)},e.useSubscription=function(e,r){const o=t.useRef(r);o.current=r;const n=t.useContext(s),i=e.client||n;if(!i)throw Error("useSubscription() requires a client to be passed in the options or as a context value");const a={query:e.query,variables:e.variables};t.useEffect((()=>{const e=i.createSubscription(a).subscribe({next:e=>{o.current(e)},error:e=>{o.current({errors:e})},complete:()=>{e.unsubscribe()}});return()=>{e.unsubscribe()}}),[])},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("events")):"function"==typeof define&&define.amd?define(["exports","react","events"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GraphQLHooks={},e.React,e.EventEmitter)}(this,(function(e,t,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(t),s=o(r);const i=n.default.createContext(null);i.displayName="ClientContext";var a=class{constructor({uri:e,name:t,type:r}){this.uri=e,this.name=t,this.type=r}},u=function(e){return"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof a},c=u,l=u,f=function(e,t="",r=l){const o=new Map,n=new Map;return{clone:function e(t,s,i){let a=t;if(r(t)){a=null;const e=o.get(t);e?e.push(s):o.set(t,[s])}else{const r=Array.isArray(t)||"undefined"!=typeof FileList&&t instanceof FileList;if(r||t&&t.constructor===Object){const o=n.has(t);if(o?a=n.get(t):(a=r?[]:{},n.set(t,a)),!i.has(t)){const n=s?s+".":"",u=new Set(i).add(t);if(r){let r=0;for(const s of t){const t=e(s,n+r++,u);o||a.push(t)}}else for(const r in t){const s=e(t[r],n+r,u);o||(a[r]=s)}}}}return a}(e,t,new Set),files:o}};const h=e=>c(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe||null!==e&&"object"==typeof e&&"function"==typeof e.stream;function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=Array(t);t>r;r++)o[r]=e[r];return o}function d(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return p(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?p(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return e.length>o?{done:!1,value:e[o++]}:{done:!0}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var y=function(){function e(e){var t=this;0===e.length&&e.push((function(e,t){return t()}));for(var r,o=function(){var e,o=r.value;if("function"!=typeof o)throw Error("GraphQLClient Middleware: middleware has to be of type `function`");t.run=(e=t.run,function(r,n){e(r,(function(){o.call(t,r,n.bind.call(n,null,r))}))})},n=d(e);!(r=n()).done;)o()}return e.prototype.run=function(e,t){t.apply(this,e)},e}();var b=(e=>(e.DATA_INVALIDATED="DATA_INVALIDATED",e.DATA_UPDATED="DATA_UPDATED",e))(b||{}),E=Object.defineProperty,g=Object.defineProperties,m=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,w=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,T=(e,t)=>{for(var r in t||(t={}))O.call(t,r)&&w(e,r,t[r]);if(v)for(var r of v(t))C.call(t,r)&&w(e,r,t[r]);return e};class A{constructor(e){if(!e)throw Error("GraphQLClient: config is required as first parameter");this.fullWsTransport=e.fullWsTransport,this.subscriptionClient="function"==typeof e.subscriptionClient?e.subscriptionClient():e.subscriptionClient,this.verifyConfig(e),this.cache=e.cache,this.headers=e.headers||{},this.ssrMode=e.ssrMode,this.ssrPromises=[],this.url=e.url,this.fetch=e.fetch||("undefined"!=typeof fetch&&fetch?fetch.bind(void 0):void 0),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.middleware=new y(e.middleware||[]),this.mutationsEmitter=new s.default}verifyConfig(e){if(!e.url){if(!this.fullWsTransport)throw Error("GraphQLClient: config.url is required");if(!this.subscriptionClient)throw Error("GraphQLClient: subscriptionClient is required")}if(e.fetch&&"function"!=typeof e.fetch)throw Error("GraphQLClient: config.fetch must be a function");if(("undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement||e.ssrMode)&&!e.fetch&&"function"!=typeof 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")}setHeader(e,t){return this.headers[e]=t,this}setHeaders(e){return this.headers=e,this}removeHeader(e){return delete this.headers[e],this}logErrorResult({result:e,operation:t}){console.error("GraphQL Hooks Error"),console.groupCollapsed("---\x3e Full Error Details"),console.groupCollapsed("Operation:"),console.log(t),console.groupEnd();const r=e.error;r&&(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((e=>console.log(e))),console.groupEnd())),console.groupEnd()}generateResult({fetchError:e,httpError:t,graphQLErrors:r,data:o}){return!!(r&&r.length>0||e||t)?{data:o,error:{fetchError:e,httpError:t,graphQLErrors:r}}:{data:o}}getCacheKey(e,t={}){return{operation:e,fetchOptions:T(T({},this.fetchOptions),t.fetchOptionsOverrides)}}getCache(e){const t=this.cache?this.cache.get(e):null;if(t)return t}saveCache(e,t){this.cache&&this.cache.set(e,t)}removeCache(e){var t;null==(t=this.cache)||t.delete(e)}getFetchOptions(e,t={}){const r=T(T({method:"POST",headers:T({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;const{clone:o,files:n}=f(e,"",h),s=JSON.stringify(o);if(n.size){if(!this.FormData)throw Error("GraphQLClient: FormData must be polyfilled or passed in new GraphQLClient({ FormData })");const e=new this.FormData;e.append("operations",s);const t={};let o=0;n.forEach((e=>{t[++o]=e})),e.append("map",JSON.stringify(t)),o=0,n.forEach(((t,r)=>{e.append(""+ ++o,r,r.name)})),r.body=e}else r.headers["Content-Type"]="application/json",r.body=s;return r}request(e,t){const r=[],o=e=>r.push(e);return new Promise(((n,s)=>this.middleware.run({operation:e,client:this,addResponseHook:o,resolve:n,reject:s},(({operation:e})=>{const o=e=>{return r.length>0?(t=r,e=>t.reduce(((e,t)=>e.then(t)),Promise.resolve(e)))(e):e;var t};return this.fullWsTransport?this.requestViaWS(e).then(o).then(n).catch(s):this.url?this.requestViaHttp(e,t).then(o).then(n).catch(s):void s(Error("GraphQLClient: config.url is required"))}))))}requestViaHttp(e,t={}){let r=this.url;const o=this.getFetchOptions(e,t.fetchOptionsOverrides);if("GET"===o.method){r=r+"?"+Object.entries(e).filter((([,e])=>!!e)).map((([e,t])=>("variables"!==e&&"extensions"!==e||(t=JSON.stringify(t)),`${e}=${encodeURIComponent(t)}`))).join("&")}return this.fetch(r,o).then((e=>e.ok?e.json().then((({errors:r,data:o})=>this.generateResult({graphQLErrors:r,data:"function"==typeof t.responseReducer&&t.responseReducer(o,e)||o}))):e.text().then((t=>{const{status:r,statusText:o}=e;return this.generateResult({httpError:{status:r,statusText:o,body:t}})})))).catch((e=>this.generateResult({fetchError:e}))).then((t=>(t.error&&(this.logErrors&&this.logErrorResult({result:t,operation:e}),this.onError&&this.onError({result:t,operation:e})),t)))}requestViaWS(e){return new Promise(((t,r)=>{let o;try{const n=this.createSubscription(e).subscribe({next:e=>{o=e},error:r,complete:()=>{n.unsubscribe(),t(o)}})}catch(e){r(e)}}))}createSubscription(e){if(!this.subscriptionClient)throw Error("No SubscriptionClient! Please set in the constructor.");return"function"==typeof this.subscriptionClient.subscribe?{subscribe:t=>({unsubscribe:this.subscriptionClient.subscribe(e,t)})}:this.subscriptionClient.request(e)}invalidateQuery(e){const t="string"==typeof e?{query:e}:e,r=this.getCacheKey(t);this.cache&&r&&(this.removeCache(r),this.request(t).then((e=>{this.mutationsEmitter.emit(b.DATA_INVALIDATED,e)})).catch((e=>console.error(e))))}setQueryData(e,t){const r=this.getCacheKey("string"==typeof e?{query:e}:e);if(this.cache&&r){const e=this.cache.get(r),s=(o=T({},e),n={data:t(e.data||null)},g(o,m(n)));this.saveCache(r,s),this.mutationsEmitter.emit(b.DATA_UPDATED,s)}var o,n}}class D{constructor(e){this.fetchError=e.fetchError,this.httpError=e.httpError,this.graphQLErrors=e.graphQLErrors}}var S=Object.defineProperty,L=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,P=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;function R(e){const t={},r=[];for(const[o,n]of Object.entries(e)){const e=q(n);t[o]=e.data,null!=e.errors&&r.push(...e.errors)}return{data:t,errors:r}}function q(e){return e instanceof Error?{data:null,errors:[e]}:Array.isArray(e)?function(e){const t=Array(e.length),r=[];for(const[o,n]of e.entries()){const e=q(n);t[o]=e.data,null!=e.errors&&r.push(...e.errors)}return{data:t,errors:r}}(e):(t=e)===Object(t)?R(e):{data:e,errors:null};var t}var I=Object.prototype.hasOwnProperty;function M(e,t,r){for(r of e.keys())if(G(r,t))return r}function G(e,t){var r,o,n;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((o=e.length)===t.length)for(;o--&&G(e[o],t[o]););return-1===o}if(r===Set){if(e.size!==t.size)return!1;for(o of e){if((n=o)&&"object"==typeof n&&!(n=M(t,n)))return!1;if(!t.has(n))return!1}return!0}if(r===Map){if(e.size!==t.size)return!1;for(o of e){if((n=o[0])&&"object"==typeof n&&!(n=M(t,n)))return!1;if(!G(o[1],t.get(n)))return!1}return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((o=e.byteLength)===t.byteLength)for(;o--&&e.getInt8(o)===t.getInt8(o););return-1===o}if(ArrayBuffer.isView(e)){if((o=e.byteLength)===t.byteLength)for(;o--&&e[o]===t[o];);return-1===o}if(!r||"object"==typeof e){for(r in o=0,e){if(I.call(e,r)&&++o&&!I.call(t,r))return!1;if(!(r in t)||!G(e[r],t[r]))return!1}return Object.keys(t).length===o}}return e!=e&&t!=t}var _=Object.defineProperty,H=Object.defineProperties,x=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,U=(e,t,r)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,V=(e,t)=>{for(var r in t||(t={}))k.call(t,r)&&U(e,r,t[r]);if(N)for(var r of N(t))F.call(t,r)&&U(e,r,t[r]);return e},K=(e,t)=>H(e,x(t));const J={RESET_STATE:"RESET_STATE",LOADING:"LOADING",CACHE_HIT:"CACHE_HIT",REQUEST_RESULT:"REQUEST_RESULT"};function W(e,t){switch(t.type){case J.RESET_STATE:return e.loading?e:t.initialState;case J.LOADING:return e.error?K(V({},t.initialState),{data:e.data,loading:!0}):e.loading?e:K(V({},e),{loading:!0});case J.CACHE_HIT:return e.cacheHit&&!t.resetState?e:K(V({},t.result),{cacheHit:!0,loading:!1});case J.REQUEST_RESULT:return K(V({},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 z(e,t={}){if("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.");const r=n.default.useContext(i),o=t.client||r;if(null==o)throw Error("A client must be provided in order to use the useClientRequest hook.");const s=n.default.useRef(!0),a=n.default.useRef(null),u={query:e,variables:t.variables,operationName:t.operationName,persisted:t.persisted};(t.persisted||o.useGETForQueries&&!t.isMutation)&&(t.fetchOptionsOverrides=K(V({},t.fetchOptionsOverrides),{method:"GET"}));const c=o.getCacheKey(u,t),l=t.isMutation||t.isManual||t.skip,f=!t.skipCache&&o.cache&&c?o.cache.get(c):null,h=K(V({},f),{cacheHit:!!f,loading:!l&&!f}),[p,d]=n.default.useReducer(W,h),y=JSON.stringify(c);n.default.useEffect((()=>{t.updateData||d({type:J.RESET_STATE,initialState:h})}),[y]),n.default.useEffect((()=>(s.current=!0,()=>{s.current=!1})),[]);const E=function(e,t){const r=n.default.useRef();return G(t,r.current)||(r.current=t),n.default.useCallback(e,r.current)}((r=>{const n=V(V({},t),r),i=K(V({},u),{variables:n.variables,operationName:n.operationName});if(!s.current)return Promise.resolve({error:{fetchError:Error("fetchData should not be called after hook unmounted")},loading:!1,cacheHit:!1});const c=o.getCacheKey(i,n);a.current=c;const l=n.skipCache?null:o.getCache(c);return l?(d({type:J.CACHE_HIT,result:l,resetState:y!==JSON.stringify(p.cacheKey)}),Promise.resolve(l)):(d({type:J.LOADING,initialState:h}),o.request(i,n).then((r=>{if(n.updateData&&"function"!=typeof n.updateData)throw Error("options.updateData must be a function");const u=V({},r);if(n.useCache&&(u.useCache=!0,u.cacheKey=c,o.ssrMode)){const e={error:u.error,data:n.updateData?n.updateData(p.data,u.data):u.data};o.saveCache(c,e)}if(s.current&&c===a.current&&d({type:J.REQUEST_RESULT,updateData:n.updateData,result:u}),t.isMutation&&o.mutationsEmitter.emit(e,K(V({},i),{mutation:e,result:u})),!(null==r?void 0:r.error)&&n.onSuccess){if("function"!=typeof n.onSuccess)throw Error("options.onSuccess must be a function");n.onSuccess(r,i.variables)}return r})))}),[o,t,u]);n.default.useEffect((()=>{p.useCache&&!o.ssrMode&&o.saveCache(p.cacheKey,p)}),[o,p]);return n.default.useEffect((()=>{const e=(e,t)=>{d({type:t,result:e})},t=t=>e(t,J.REQUEST_RESULT),r=t=>e(t,J.CACHE_HIT),n=o.mutationsEmitter;return n.on(b.DATA_INVALIDATED,t),n.on(b.DATA_UPDATED,r),()=>{n&&(n.removeListener(b.DATA_INVALIDATED,t),n.removeListener(b.DATA_UPDATED,r))}}),[]),[E,p,(e={})=>d({type:J.RESET_STATE,initialState:V(V({},h),e)})]}var B=Object.defineProperty,$=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertySymbols,Z=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable,te=(e,t,r)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,re=(e,t)=>{for(var r in t||(t={}))Z.call(t,r)&&te(e,r,t[r]);if(X)for(var r of X(t))ee.call(t,r)&&te(e,r,t[r]);return e};const oe={useCache:!0,skip:!1,throwErrors:!1};var ne=Object.defineProperty,se=Object.getOwnPropertySymbols,ie=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable,ue=(e,t,r)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ce=Object.defineProperty,le=Object.getOwnPropertySymbols,fe=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,pe=(e,t,r)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;e.ClientContext=i,e.GraphQLClient=A,e.LocalGraphQLClient=class extends A{constructor(e){if(super(((e,t)=>{for(var r in t||(t={}))j.call(t,r)&&P(e,r,t[r]);if(L)for(var r of L(t))Q.call(t,r)&&P(e,r,t[r]);return e})({url:""},e)),this.localQueries=e.localQueries,this.requestDelayMs=e.requestDelayMs||0,!this.localQueries)throw Error("LocalGraphQLClient: `localQueries` object required in the constructor options")}verifyConfig(){}request(e){if(!this.localQueries[e.query])throw Error("LocalGraphQLClient: no query match for: "+e.query);return(t=this.requestDelayMs,new Promise((e=>{setTimeout(e,t)}))).then((()=>Promise.resolve(this.localQueries[e.query](e.variables,e.operationName)))).then((e=>{if(e instanceof D)return{error:e};const{data:t,errors:r}=R(e);return r.length>0?{data:t,error:new D({graphQLErrors:r})}:{data:t}}));var t}},e.LocalGraphQLError=D,e.useClientRequest=z,e.useManualQuery=(e,t={})=>z(e,((e,t)=>{for(var r in t||(t={}))fe.call(t,r)&&pe(e,r,t[r]);if(le)for(var r of le(t))he.call(t,r)&&pe(e,r,t[r]);return e})({useCache:!0,isManual:!0},t)),e.useMutation=(e,t={})=>z(e,((e,t)=>{for(var r in t||(t={}))ie.call(t,r)&&ue(e,r,t[r]);if(se)for(var r of se(t))ae.call(t,r)&&ue(e,r,t[r]);return e})({isMutation:!0},t)),e.useQuery=function(e,t={}){const r=re(re({},oe),t),o=n.default.useContext(i),s=t.client||o,[a,u]=n.default.useState(!1),[c,l]=z(e,r);if(!s)throw Error("useQuery() requires a client to be passed in the options or as a context value");if(s.ssrMode&&!1!==t.ssr&&!a&&!t.skipCache&&!t.skip){if(!l.data&&!l.error){const e=c();s.ssrPromises.push(e)}u(!0)}const f=JSON.stringify(r);n.default.useEffect((()=>{r.skip||c()}),[e,f]),n.default.useEffect((()=>{if(l.error&&r.throwErrors)throw l.error}),[l.error,r.throwErrors]);const h=n.default.useCallback(((e={})=>c(re({skipCache:!0,updateData:(e,t)=>t},e))),[c]);return n.default.useEffect((function(){const e=(o={},(Array.isArray(r=t.refetchAfterMutations)?r:[r]).forEach((function(e){if(null!=e){var t=typeof e;if("string"===t)o[e]={};else if("object"===t){var r=e.refetchOnMutationError;o[e.mutation]={filter:e.filter,refetchOnMutationError:void 0===r||r}}}})),o);var r,o;const n=Object.keys(e),i=({mutation:t,variables:r,result:o})=>{const{filter:n,refetchOnMutationError:s}=e[t];(!n||r&&n(r))&&(s||!o.error)&&h()};return n.forEach((e=>{s.mutationsEmitter.on(e,i)})),()=>{n.forEach((e=>{s.mutationsEmitter.removeListener(e,i)}))}}),[t.refetchAfterMutations,h,s.mutationsEmitter]),p=re({},l),$(p,Y({refetch:h}));var p},e.useQueryClient=function(){return t.useContext(i)},e.useSubscription=function(e,r){const o=t.useRef(r);o.current=r;const n=t.useContext(i),s=e.client||n;if(!s)throw Error("useSubscription() requires a client to be passed in the options or as a context value");const a={query:e.query,variables:e.variables};t.useEffect((()=>{const e=s.createSubscription(a).subscribe({next:e=>{o.current(e)},error:e=>{o.current({errors:e})},complete:()=>{e.unsubscribe()}});return()=>{e.unsubscribe()}}),[])},Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -479,3 +479,8 @@ import React, { useContext, useRef, useEffect } from 'react';

}
return { data: result };
const { data, errors } = collectErrorsFromObject(result);
if (errors.length > 0) {
return { data, error: new LocalGraphQLError({ graphQLErrors: errors }) };
} else {
return { data };
}
});

@@ -489,2 +494,40 @@ }

}
function isObject(o) {
return o === Object(o);
}
function collectErrorsFromObject(objectIn) {
const data = {};
const errors = [];
for (const [key, value] of Object.entries(objectIn)) {
const child = collectErrorsFromChild(value);
data[key] = child.data;
if (child.errors != null) {
errors.push(...child.errors);
}
}
return { data, errors };
}
function collectErrorsFromArray(arrayIn) {
const data = Array(arrayIn.length);
const errors = [];
for (const [idx, entry] of arrayIn.entries()) {
const child = collectErrorsFromChild(entry);
data[idx] = child.data;
if (child.errors != null) {
errors.push(...child.errors);
}
}
return { data, errors };
}
function collectErrorsFromChild(entry) {
if (entry instanceof Error) {
return { data: null, errors: [entry] };
} else if (Array.isArray(entry)) {
return collectErrorsFromArray(entry);
} else if (isObject(entry)) {
return collectErrorsFromObject(entry);
} else {
return { data: entry, errors: null };
}
}

@@ -491,0 +534,0 @@ var __defProp$3 = Object.defineProperty;

declare function _default(): boolean;
export default _default;

@@ -0,0 +0,0 @@ import React from 'react';

/**
* Checks values of refetchAfterMutations public option and maps them to an object
* @typedef {import('../index').RefetchAferMutationsData} RefetchAferMutationsData
* @typedef {import('../index').RefetchAfterMutationsData} RefetchAfterMutationsData
*
* @param {RefetchAferMutationsData} refetchAfterMutations
* @param {RefetchAfterMutationsData} refetchAfterMutations
* @returns {object}

@@ -12,2 +12,2 @@ */

*/
export type RefetchAferMutationsData = any;
export type RefetchAfterMutationsData = any;

@@ -0,0 +0,0 @@ export declare enum Events {

@@ -488,3 +488,8 @@ 'use strict';

}
return { data: result };
const { data, errors } = collectErrorsFromObject(result);
if (errors.length > 0) {
return { data, error: new LocalGraphQLError({ graphQLErrors: errors }) };
} else {
return { data };
}
});

@@ -498,2 +503,40 @@ }

}
function isObject(o) {
return o === Object(o);
}
function collectErrorsFromObject(objectIn) {
const data = {};
const errors = [];
for (const [key, value] of Object.entries(objectIn)) {
const child = collectErrorsFromChild(value);
data[key] = child.data;
if (child.errors != null) {
errors.push(...child.errors);
}
}
return { data, errors };
}
function collectErrorsFromArray(arrayIn) {
const data = Array(arrayIn.length);
const errors = [];
for (const [idx, entry] of arrayIn.entries()) {
const child = collectErrorsFromChild(entry);
data[idx] = child.data;
if (child.errors != null) {
errors.push(...child.errors);
}
}
return { data, errors };
}
function collectErrorsFromChild(entry) {
if (entry instanceof Error) {
return { data: null, errors: [entry] };
} else if (Array.isArray(entry)) {
return collectErrorsFromArray(entry);
} else if (isObject(entry)) {
return collectErrorsFromObject(entry);
} else {
return { data: entry, errors: null };
}
}

@@ -500,0 +543,0 @@ var __defProp$3 = Object.defineProperty;

@@ -0,0 +0,0 @@ /// <reference types="node" />

@@ -0,0 +0,0 @@ import ClientContext from './ClientContext';

import { ExtractableFile } from 'extract-files';
declare const isExtractableFileEnhanced: <TFile = ExtractableFile>(value: any) => value is TFile;
export default isExtractableFileEnhanced;

@@ -0,0 +0,0 @@ import GraphQLClient from './GraphQLClient';

@@ -0,0 +0,0 @@ import { APIError, HttpError } from './types/common-types';

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ import { MiddlewareFunction } from '../types/common-types';

@@ -0,0 +0,0 @@ import { MiddlewareFunction } from '../../types/common-types';

@@ -0,0 +0,0 @@ import { MiddlewareFunction } from '../../types/common-types';

@@ -0,0 +0,0 @@ import { Client as GraphQLWsClient } from 'graphql-ws';

@@ -0,0 +0,0 @@ import { UseClientRequestOptions, FetchData, UseClientRequestResult, ResetFunction } from './types/common-types';

import { UseClientRequestOptions, FetchData, UseClientRequestResult, ResetFunction } from './types/common-types';
declare const useMutation: <ResponseData = any, Variables = object, TGraphQLError = object>(query: string, options?: Omit<UseClientRequestOptions<ResponseData, Variables, import("./types/common-types").GraphQLResponseError>, "isMutation">) => [FetchData<ResponseData, Variables, TGraphQLError>, UseClientRequestResult<ResponseData, TGraphQLError>, ResetFunction];
export default useMutation;
import { UseQueryOptions, UseQueryResult } from './types/common-types';
declare function useQuery<ResponseData = any, Variables = object, TGraphQLError = object>(query: string, opts?: UseQueryOptions<ResponseData, Variables>): UseQueryResult<ResponseData, Variables, TGraphQLError>;
export default useQuery;
declare function useQueryClient(): import("./GraphQLClient").default | null;
export default useQueryClient;

@@ -0,0 +0,0 @@ import { UseSubscriptionOperation } from './types/common-types';

@@ -0,0 +0,0 @@ /**

{
"name": "graphql-hooks",
"version": "6.2.3",
"version": "6.3.0",
"description": "Graphql Hooks",

@@ -50,3 +50,3 @@ "main": "lib/graphql-hooks.js",

"formdata-node": "^4.3.2",
"graphql-hooks-memcache": "^3.1.2",
"graphql-hooks-memcache": "^3.1.3",
"graphql-hooks-ssr": "^3.0.1",

@@ -68,3 +68,3 @@ "graphql-ws": "^5.5.5",

"homepage": "https://github.com/nearform/graphql-hooks#readme",
"gitHead": "ed5ff7c752eff436adf64c77d311254d3611c188"
"gitHead": "c7952cacaf3d541583f4a5b469ee4245cba31208"
}

@@ -1151,2 +1151,24 @@ # graphql-hooks

It is also possible to mock a partial error response (for example where one resolver encounters an error but other resolvers return successfully). To do this, include `Error` objects in the mock query resolver:
```js
import { allPostsQuery } from '../src/components/Post'
const localQueries = {
[allPostsQuery]: () => ({
field1: 'foo',
field2: new Error('something went wrong'),
nested: {
field3: new Error('a nested error')
}
})
}
const client = new LocalGraphQLClient({ localQueries })
const result = await client.request({
query: allPostsQuery
})
console.log(result.data) // The `data` object will have the correct value for `field1` and `null` for any fields returning `Error` objects
console.log(result.error) // The `error` object will have a `graphQLErrors` array containing each of the `Error` objects created above
```
### Testing with React

@@ -1153,0 +1175,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc