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
0
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 8.1.0 to 8.2.0

5

dist/graphql-hooks.js

@@ -1476,2 +1476,5 @@ (function (global, factory) {

useDeepCompareEffect(() => {
if (options.skip) {
return;
}
const request = {

@@ -1496,3 +1499,3 @@ query: options.query,

};
}, [options.query, options.variables]);
}, [options.query, options.variables, options.skip]);
}

@@ -1499,0 +1502,0 @@

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 n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=n(t),s=o(t),a=n(r);const u=i.default.createContext(null);function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}u.displayName="ClientContext";const l=class{constructor({uri:e,name:t,type:r}){this.uri=e,this.name=t,this.type=r}};var f=function(e){return"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof l},h=c(f);const p=f;var d=function(e,t="",r=p){const n=new Map,o=new Map;return{clone:function e(t,i,s){let a=t;if(r(t)){a=null;const e=n.get(t);e?e.push(i):n.set(t,[i])}else{const r=Array.isArray(t)||"undefined"!=typeof FileList&&t instanceof FileList;if(r||t&&t.constructor===Object){const n=o.has(t);if(n?a=o.get(t):(a=r?[]:{},o.set(t,a)),!s.has(t)){const o=i?i+".":"",u=new Set(s).add(t);if(r){let r=0;for(const i of t){const t=e(i,o+r++,u);n||a.push(t)}}else for(const r in t){const i=e(t[r],o+r,u);n||(a[r]=i)}}}}return a}(e,t,new Set),files:n}},y=c(d);const b=e=>h(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe||null!==e&&"object"==typeof e&&"function"==typeof e.stream;function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function m(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 v(e,t);var r={}.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)?v(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return e.length>n?{done:!1,value:e[n++]}:{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 g=function(){function e(e){var t=this;0===e.length&&e.push((function(e,t){return t()}));for(var r,n=function(){var e=r.value;if("function"!=typeof e)throw Error("GraphQLClient Middleware: middleware has to be of type `function`");t.run=function(r){return function(n,o){r(n,(function(){e.call(t,n,o.bind.call(o,null,n))}))}}(t.run)},o=m(e);!(r=o()).done;)n()}return e.prototype.run=function(e,t){t.apply(this,e)},e}(),E="OperationDefinition",O=function(e){return e[e.Const=1]="Const",e[e.Var=2]="Var",e[e.Int=3]="Int",e[e.Float=4]="Float",e[e.BlockString=5]="BlockString",e[e.String=6]="String",e[e.Enum=7]="Enum",e}(O||{}),D=function(e){return e[e.Spread=1]="Spread",e[e.Name=2]="Name",e}(D||{});function C(e,t,r){for(var n="",o=0;e.length>o;o++)o&&(n+=t),n+=r(e[o]);return n}var w="\n",S={OperationDefinition(e){var t=e.operation;return e.name&&(t+=" "+e.name.value),e.variableDefinitions&&e.variableDefinitions.length&&(e.name||(t+=" "),t+="("+C(e.variableDefinitions,", ",S.VariableDefinition)+")"),e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),"query"!==t?t+" "+S.SelectionSet(e.selectionSet):S.SelectionSet(e.selectionSet)},VariableDefinition(e){var t=S.Variable(e.variable)+": "+A(e.type);return e.defaultValue&&(t+=" = "+A(e.defaultValue)),e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t},Field(e){var t=e.alias?e.alias.value+": "+e.name.value:e.name.value;if(e.arguments&&e.arguments.length){var r=C(e.arguments,", ",S.Argument);t+=t.length+r.length+2>80?"("+(w+=" ")+C(e.arguments,w,S.Argument)+(w=w.slice(0,-2))+")":"("+r+")"}return e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),e.selectionSet&&e.selectionSet.selections.length&&(t+=" "+S.SelectionSet(e.selectionSet)),t},StringValue:e=>e.block?function(e){return'"""\n'+e.replace(/"""/g,'\\"""')+'\n"""'}(e.value).replace(/\n/g,w):function(e){return JSON.stringify(e)}(e.value),BooleanValue:e=>""+e.value,NullValue:e=>"null",IntValue:e=>e.value,FloatValue:e=>e.value,EnumValue:e=>e.value,Name:e=>e.value,Variable:e=>"$"+e.name.value,ListValue:e=>"["+C(e.values,", ",A)+"]",ObjectValue:e=>"{"+C(e.fields,", ",S.ObjectField)+"}",ObjectField:e=>e.name.value+": "+A(e.value),Document:e=>e.definitions&&e.definitions.length?C(e.definitions,"\n\n",A):"",SelectionSet:e=>"{"+(w+=" ")+C(e.selections,w,A)+(w=w.slice(0,-2))+"}",Argument:e=>e.name.value+": "+A(e.value),FragmentSpread(e){var t="..."+e.name.value;return e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t},InlineFragment(e){var t="...";return e.typeCondition&&(t+=" on "+e.typeCondition.name.value),e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t+" "+S.SelectionSet(e.selectionSet)},FragmentDefinition(e){var t="fragment "+e.name.value;return t+=" on "+e.typeCondition.name.value,e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t+" "+S.SelectionSet(e.selectionSet)},Directive(e){var t="@"+e.name.value;return e.arguments&&e.arguments.length&&(t+="("+C(e.arguments,", ",S.Argument)+")"),t},NamedType:e=>e.name.value,ListType:e=>"["+A(e.type)+"]",NonNullType:e=>A(e.type)+"!"},A=e=>S[e.kind](e);function j(e){return"string"==typeof e?e:function(e){return w="\n",S[e.kind]?S[e.kind](e):""}(e)}var T=(e=>(e.DATA_INVALIDATED="DATA_INVALIDATED",e.DATA_UPDATED="DATA_UPDATED",e))(T||{}),L=Object.defineProperty,P=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,F=(e,t,r)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,k=(e,t)=>{for(var r in t||(t={}))M.call(t,r)&&F(e,r,t[r]);if(q)for(var r of q(t))R.call(t,r)&&F(e,r,t[r]);return e},I=(e,t,r)=>F(e,"symbol"!=typeof t?t+"":t,r);class V{constructor(e){if(I(this,"url"),I(this,"ssrPromises"),I(this,"FormData"),I(this,"fetch"),I(this,"fetchOptions"),I(this,"logErrors"),I(this,"useGETForQueries"),I(this,"middleware"),I(this,"mutationsEmitter"),I(this,"cache"),I(this,"headers"),I(this,"ssrMode"),I(this,"subscriptionClient"),I(this,"fullWsTransport"),I(this,"onError"),!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 g(e.middleware||[]),this.mutationsEmitter=new a.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:n,headers:o}){return!!(r&&r.length>0||e||t)?{data:n,error:{fetchError:e,httpError:t,graphQLErrors:r},headers:o}:{data:n,headers:o}}getCacheKey(e,t={}){return{operation:e,fetchOptions:k(k({},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=k(k({method:"POST",headers:k({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;const{clone:n,files:o}=y(e,"",b),i=JSON.stringify(n);if(o.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 n=0;o.forEach((e=>{t[++n]=e})),e.append("map",JSON.stringify(t)),n=0,o.forEach(((t,r)=>{e.append(""+ ++n,r,r.name)})),r.body=e}else r.headers["Content-Type"]="application/json",r.body=i;return r}request(e,t){const r=[],n=e=>r.push(e);return new Promise(((o,i)=>this.middleware.run({operation:e,client:this,addResponseHook:n,resolve:o,reject:i},(({operation:e})=>{const n=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(n).then(o).catch(i):this.url?this.requestViaHttp(e,t).then(n).then(o).catch(i):void i(Error("GraphQLClient: config.url is required"))}))))}requestViaHttp(e,t={}){let r=this.url;const n=this.getFetchOptions(e,t.fetchOptionsOverrides);if("GET"===n.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,n).then((e=>e.ok?e.json().then((({errors:r,data:n})=>this.generateResult({graphQLErrors:r,data:G(t.responseReducer,n,e),headers:e.headers}))):e.text().then((t=>{const{status:r,statusText:n}=e;return this.generateResult({httpError:{status:r,statusText:n,body:t},headers:e.headers})})))).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 n;try{const o=this.createSubscription(e).subscribe({next:e=>{n=e},error:r,complete:()=>{o.unsubscribe(),t(n)}})}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(T.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=(n=k({},e),o={data:t(e.data||null)},P(n,Q(o)));this.saveCache(r,i),this.mutationsEmitter.emit(T.DATA_UPDATED,i)}var n,o}}function G(e,t,r){return"function"==typeof e?e(t,r):t}var N=Object.defineProperty,x=(e,t,r)=>((e,t,r)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class _{constructor(e){x(this,"fetchError"),x(this,"httpError"),x(this,"graphQLErrors"),this.fetchError=e.fetchError,this.httpError=e.httpError,this.graphQLErrors=e.graphQLErrors}}var H=Object.defineProperty,U=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,W=(e,t,r)=>J(e,"symbol"!=typeof t?t+"":t,r);function z(e){return e instanceof Error?{data:null,errors:[e]}:Array.isArray(e)?function(e){const t=Array(e.length),r=[];for(const[n,o]of e.entries()){const e=z(o);t[n]=e.data,null!=e.errors&&r.push(...e.errors)}return{data:t,errors:r}}(e):function(e){return e===Object(e)}(e)?function(e){const t={},r=[];for(const[n,o]of Object.entries(e)){const e=z(o);t[n]=e.data,null!=e.errors&&r.push(...e.errors)}return{data:t,errors:r}}(e):{data:e,errors:null}}var $=Object.prototype.hasOwnProperty;function X(e,t,r){for(r of e.keys())if(Y(r,t))return r}function Y(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--&&Y(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=X(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=X(t,o)))return!1;if(!Y(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($.call(e,r)&&++n&&!$.call(t,r))return!1;if(!(r in t)||!Y(e[r],t[r]))return!1}return Object.keys(t).length===n}}return e!=e&&t!=t}function Z(e){var t=s.useRef(e),r=s.useRef(0);return Y(e,t.current)||(t.current=e,r.current+=1),s.useMemo((function(){return t.current}),[r.current])}var ee=Object.defineProperty,te=Object.defineProperties,re=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,oe=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable,se=(e,t,r)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ae=(e,t)=>{for(var r in t||(t={}))oe.call(t,r)&&se(e,r,t[r]);if(ne)for(var r of ne(t))ie.call(t,r)&&se(e,r,t[r]);return e},ue=(e,t)=>te(e,re(t));const ce="RESET_STATE",le="LOADING",fe="CACHE_HIT",he="REQUEST_RESULT",pe="DATA_UPDATED";function de(e,t){switch(t.type){case ce:return e.loading?e:t.initialState;case le:return e.error?ue(ae({},t.initialState),{data:e.data,loading:!0}):e.loading?e:ue(ae({},e),{loading:!0});case pe:return ue(ae({},e),{data:t.result.data});case fe:return e.cacheHit&&!t.resetState?e:ue(ae({},t.result),{cacheHit:!0,loading:!1});case he:return ue(ae({},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 ye(e,t={}){var r;const n=j(e),o=null!=(r=t.operationName)?r:function(e){var t,r;let n;if("string"!=typeof e){const o=e.definitions.filter((e=>e.kind===E));1===o.length&&(n=null==(r=null==(t=o[0])?void 0:t.name)?void 0:r.value)}return n}(e),s=i.default.useContext(u),a=t.client||s;if(null==a)throw Error("A client must be provided in order to use the useClientRequest hook.");const c=i.default.useRef(!0),l=i.default.useRef(null),f={query:n,variables:t.variables,operationName:o,persisted:t.persisted};(t.persisted||a.useGETForQueries&&!t.isMutation)&&(t.fetchOptionsOverrides=ue(ae({},t.fetchOptionsOverrides),{method:"GET"}));const h=a.getCacheKey(f,t),p=t.isMutation||t.isManual||t.skip,d=!t.skipCache&&a.cache&&h?a.cache.get(h):null,y=ue(ae({},d),{cacheHit:!!d,loading:!p&&!d}),[b,v]=i.default.useReducer(de,y),m=JSON.stringify(h);i.default.useEffect((()=>{t.updateData||v({type:ce,initialState:y})}),[m]),i.default.useEffect((()=>(c.current=!0,()=>{c.current=!1})),[]);const g=i.default.useCallback((e=>{const r=ae(ae({},t),e),o=ue(ae({},f),{variables:r.variables,operationName:r.operationName});if(!c.current)return Promise.resolve({error:{fetchError:Error("fetchData should not be called after hook unmounted")},loading:!1,cacheHit:!1});const i=a.getCacheKey(o,r);l.current=i;const s=r.skipCache?null:a.getCache(i);return s?(v({type:fe,result:s,resetState:m!==JSON.stringify(b.cacheKey)}),Promise.resolve(s)):(v({type:le,initialState:y}),a.request(o,r).then((e=>{if(r.updateData&&"function"!=typeof r.updateData)throw Error("options.updateData must be a function");const s=ae({},e);if(r.useCache&&(s.useCache=!0,s.cacheKey=i,a.ssrMode)){const e={error:s.error,data:r.updateData?r.updateData(b.data,s.data):s.data};a.saveCache(i,e)}if(c.current&&i===l.current&&v({type:he,updateData:r.updateData,result:s}),t.isMutation&&a.mutationsEmitter.emit(n,ue(ae({},o),{mutation:n,result:s})),!(null==e?void 0:e.error)&&r.onSuccess){if("function"!=typeof r.onSuccess)throw Error("options.onSuccess must be a function");r.onSuccess(e,o.variables)}return e})))}),Z([a,t,f]));i.default.useEffect((()=>{b.useCache&&!a.ssrMode&&a.saveCache(b.cacheKey,b)}),[a,b]);return i.default.useEffect((()=>{const e=(e,t)=>{v({type:t,result:e})},t=t=>e(t,he),r=t=>e(t,pe),n=a.mutationsEmitter;return n.on(T.DATA_INVALIDATED,t),n.on(T.DATA_UPDATED,r),()=>{n&&(n.removeListener(T.DATA_INVALIDATED,t),n.removeListener(T.DATA_UPDATED,r))}}),[]),[g,b,(e={})=>v({type:ce,initialState:ae(ae({},y),e)})]}var be=Object.defineProperty,ve=Object.defineProperties,me=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,Ee=Object.prototype.hasOwnProperty,Oe=Object.prototype.propertyIsEnumerable,De=(e,t,r)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ce=(e,t)=>{for(var r in t||(t={}))Ee.call(t,r)&&De(e,r,t[r]);if(ge)for(var r of ge(t))Oe.call(t,r)&&De(e,r,t[r]);return e};const we={useCache:!0,skip:!1,throwErrors:!1};var Se=Object.defineProperty,Ae=Object.getOwnPropertySymbols,je=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,Le=(e,t,r)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Pe=Object.defineProperty,Qe=Object.getOwnPropertySymbols,qe=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,Re=(e,t,r)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;e.ClientContext=u,e.GraphQLClient=V,e.LocalGraphQLClient=class extends V{constructor(e){if(super(((e,t)=>{for(var r in t||(t={}))K.call(t,r)&&J(e,r,t[r]);if(U)for(var r of U(t))B.call(t,r)&&J(e,r,t[r]);return e})({url:"http://localhost"},e)),W(this,"localQueries"),W(this,"requestDelayMs"),this.localQueries=e.localQueries,this.requestDelayMs=e.requestDelayMs||0,!this.localQueries)throw Error("LocalGraphQLClient: `localQueries` object required in the constructor options")}verifyConfig(){}requestViaHttp(e,t={}){return(r=this.requestDelayMs,new Promise((e=>{setTimeout(e,r)}))).then((()=>{if(!e.query||!this.localQueries[e.query])throw Error("LocalGraphQLClient: no query match for: "+e.query);const r=this.localQueries[e.query](e.variables,e.operationName);return G(t.responseReducer,r,new Response)}));var r}request(e,t){return super.request(e,t).then((e=>{if(e instanceof _)return{error:e};const{data:t,errors:r}=z(e);return r&&r.length>0?{data:t,error:new _({graphQLErrors:r})}:{data:t}}))}},e.LocalGraphQLError=_,e.useClientRequest=ye,e.useManualQuery=(e,t={})=>ye(e,((e,t)=>{for(var r in t||(t={}))qe.call(t,r)&&Re(e,r,t[r]);if(Qe)for(var r of Qe(t))Me.call(t,r)&&Re(e,r,t[r]);return e})({useCache:!0,isManual:!0},t)),e.useMutation=(e,t={})=>ye(e,((e,t)=>{for(var r in t||(t={}))je.call(t,r)&&Le(e,r,t[r]);if(Ae)for(var r of Ae(t))Te.call(t,r)&&Le(e,r,t[r]);return e})({isMutation:!0},t)),e.useQuery=function(e,t={}){const r=Ce(Ce({},we),t),n=i.default.useContext(u),o=t.client||n,[s,a]=i.default.useState(!1),[c,l]=ye(e,r);if(!o)throw Error("useQuery() requires a client to be passed in the options or as a context value");if(o.ssrMode&&!1!==t.ssr&&!s&&!t.skipCache&&!t.skip){if(!l.data&&!l.error){const e=c();o.ssrPromises.push(e)}a(!0)}const f=((e,t)=>{var r={};for(var n in e)Ee.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&ge)for(var n of ge(e))0>t.indexOf(n)&&Oe.call(e,n)&&(r[n]=e[n]);return r})(r,["client"]),h=JSON.stringify(f);i.default.useEffect((()=>{r.skip||c()}),[e,h]),i.default.useEffect((()=>{if(l.error&&r.throwErrors)throw l.error}),[l.error,r.throwErrors]);const p=i.default.useCallback(((e={})=>c(Ce({skipCache:!0,updateData:(e,t)=>t},e))),[c]);return i.default.useEffect((function(){const e=function(e){if(!e)return{};const t={};return(Array.isArray(e)?e:[e]).forEach((e=>{var r;if(null!=e)if("string"==typeof e)t[e]={};else if("object"==typeof(r=e)&&null!=r&&"mutation"in r){const{filter:r,mutation:n,refetchOnMutationError:o=!0}=e;t[n]={filter:r,refetchOnMutationError:o}}else(function(e){return"object"==typeof e&&null!=e&&"kind"in e})(e)&&(t[j(e)]={})})),t}(t.refetchAfterMutations),r=Object.keys(e),n=({mutation:t,variables:r,result:n})=>{const{filter:o,refetchOnMutationError:i}=e[t];(!o||r&&o(r))&&(i||!n.error)&&p()};return r.forEach((e=>{o.mutationsEmitter.on(e,n)})),()=>{r.forEach((e=>{o.mutationsEmitter.removeListener(e,n)}))}}),[t.refetchAfterMutations,p,o.mutationsEmitter]),d=Ce({},l),ve(d,me({refetch:p}));var d},e.useQueryClient=function(){return t.useContext(u)},e.useSubscription=function(e,r){const n=t.useRef(r);n.current=r;const o=t.useContext(u),i=e.client||o;if(!i)throw Error("useSubscription() requires a client to be passed in the options or as a context value");!function(e,t){s.useEffect(e,Z(t))}((()=>{const t=i.createSubscription({query:e.query,variables:e.variables}).subscribe({next:e=>{n.current(e)},error:e=>{n.current({errors:e})},complete:()=>{t.unsubscribe()}});return()=>{t.unsubscribe()}}),[e.query,e.variables])},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 n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=n(t),s=o(t),a=n(r);const u=i.default.createContext(null);function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}u.displayName="ClientContext";const l=class{constructor({uri:e,name:t,type:r}){this.uri=e,this.name=t,this.type=r}};var f=function(e){return"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof l},h=c(f);const p=f;var d=function(e,t="",r=p){const n=new Map,o=new Map;return{clone:function e(t,i,s){let a=t;if(r(t)){a=null;const e=n.get(t);e?e.push(i):n.set(t,[i])}else{const r=Array.isArray(t)||"undefined"!=typeof FileList&&t instanceof FileList;if(r||t&&t.constructor===Object){const n=o.has(t);if(n?a=o.get(t):(a=r?[]:{},o.set(t,a)),!s.has(t)){const o=i?i+".":"",u=new Set(s).add(t);if(r){let r=0;for(const i of t){const t=e(i,o+r++,u);n||a.push(t)}}else for(const r in t){const i=e(t[r],o+r,u);n||(a[r]=i)}}}}return a}(e,t,new Set),files:n}},y=c(d);const b=e=>h(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe||null!==e&&"object"==typeof e&&"function"==typeof e.stream;function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function m(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 v(e,t);var r={}.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)?v(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return e.length>n?{done:!1,value:e[n++]}:{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 g=function(){function e(e){var t=this;0===e.length&&e.push((function(e,t){return t()}));for(var r,n=function(){var e=r.value;if("function"!=typeof e)throw Error("GraphQLClient Middleware: middleware has to be of type `function`");t.run=function(r){return function(n,o){r(n,(function(){e.call(t,n,o.bind.call(o,null,n))}))}}(t.run)},o=m(e);!(r=o()).done;)n()}return e.prototype.run=function(e,t){t.apply(this,e)},e}(),E="OperationDefinition",O=function(e){return e[e.Const=1]="Const",e[e.Var=2]="Var",e[e.Int=3]="Int",e[e.Float=4]="Float",e[e.BlockString=5]="BlockString",e[e.String=6]="String",e[e.Enum=7]="Enum",e}(O||{}),D=function(e){return e[e.Spread=1]="Spread",e[e.Name=2]="Name",e}(D||{});function C(e,t,r){for(var n="",o=0;e.length>o;o++)o&&(n+=t),n+=r(e[o]);return n}var w="\n",S={OperationDefinition(e){var t=e.operation;return e.name&&(t+=" "+e.name.value),e.variableDefinitions&&e.variableDefinitions.length&&(e.name||(t+=" "),t+="("+C(e.variableDefinitions,", ",S.VariableDefinition)+")"),e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),"query"!==t?t+" "+S.SelectionSet(e.selectionSet):S.SelectionSet(e.selectionSet)},VariableDefinition(e){var t=S.Variable(e.variable)+": "+A(e.type);return e.defaultValue&&(t+=" = "+A(e.defaultValue)),e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t},Field(e){var t=e.alias?e.alias.value+": "+e.name.value:e.name.value;if(e.arguments&&e.arguments.length){var r=C(e.arguments,", ",S.Argument);t+=t.length+r.length+2>80?"("+(w+=" ")+C(e.arguments,w,S.Argument)+(w=w.slice(0,-2))+")":"("+r+")"}return e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),e.selectionSet&&e.selectionSet.selections.length&&(t+=" "+S.SelectionSet(e.selectionSet)),t},StringValue:e=>e.block?function(e){return'"""\n'+e.replace(/"""/g,'\\"""')+'\n"""'}(e.value).replace(/\n/g,w):function(e){return JSON.stringify(e)}(e.value),BooleanValue:e=>""+e.value,NullValue:e=>"null",IntValue:e=>e.value,FloatValue:e=>e.value,EnumValue:e=>e.value,Name:e=>e.value,Variable:e=>"$"+e.name.value,ListValue:e=>"["+C(e.values,", ",A)+"]",ObjectValue:e=>"{"+C(e.fields,", ",S.ObjectField)+"}",ObjectField:e=>e.name.value+": "+A(e.value),Document:e=>e.definitions&&e.definitions.length?C(e.definitions,"\n\n",A):"",SelectionSet:e=>"{"+(w+=" ")+C(e.selections,w,A)+(w=w.slice(0,-2))+"}",Argument:e=>e.name.value+": "+A(e.value),FragmentSpread(e){var t="..."+e.name.value;return e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t},InlineFragment(e){var t="...";return e.typeCondition&&(t+=" on "+e.typeCondition.name.value),e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t+" "+S.SelectionSet(e.selectionSet)},FragmentDefinition(e){var t="fragment "+e.name.value;return t+=" on "+e.typeCondition.name.value,e.directives&&e.directives.length&&(t+=" "+C(e.directives," ",S.Directive)),t+" "+S.SelectionSet(e.selectionSet)},Directive(e){var t="@"+e.name.value;return e.arguments&&e.arguments.length&&(t+="("+C(e.arguments,", ",S.Argument)+")"),t},NamedType:e=>e.name.value,ListType:e=>"["+A(e.type)+"]",NonNullType:e=>A(e.type)+"!"},A=e=>S[e.kind](e);function j(e){return"string"==typeof e?e:function(e){return w="\n",S[e.kind]?S[e.kind](e):""}(e)}var T=(e=>(e.DATA_INVALIDATED="DATA_INVALIDATED",e.DATA_UPDATED="DATA_UPDATED",e))(T||{}),L=Object.defineProperty,P=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,k=(e,t,r)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,F=(e,t)=>{for(var r in t||(t={}))M.call(t,r)&&k(e,r,t[r]);if(q)for(var r of q(t))R.call(t,r)&&k(e,r,t[r]);return e},I=(e,t,r)=>k(e,"symbol"!=typeof t?t+"":t,r);class V{constructor(e){if(I(this,"url"),I(this,"ssrPromises"),I(this,"FormData"),I(this,"fetch"),I(this,"fetchOptions"),I(this,"logErrors"),I(this,"useGETForQueries"),I(this,"middleware"),I(this,"mutationsEmitter"),I(this,"cache"),I(this,"headers"),I(this,"ssrMode"),I(this,"subscriptionClient"),I(this,"fullWsTransport"),I(this,"onError"),!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 g(e.middleware||[]),this.mutationsEmitter=new a.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:n,headers:o}){return!!(r&&r.length>0||e||t)?{data:n,error:{fetchError:e,httpError:t,graphQLErrors:r},headers:o}:{data:n,headers:o}}getCacheKey(e,t={}){return{operation:e,fetchOptions:F(F({},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=F(F({method:"POST",headers:F({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;const{clone:n,files:o}=y(e,"",b),i=JSON.stringify(n);if(o.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 n=0;o.forEach((e=>{t[++n]=e})),e.append("map",JSON.stringify(t)),n=0,o.forEach(((t,r)=>{e.append(""+ ++n,r,r.name)})),r.body=e}else r.headers["Content-Type"]="application/json",r.body=i;return r}request(e,t){const r=[],n=e=>r.push(e);return new Promise(((o,i)=>this.middleware.run({operation:e,client:this,addResponseHook:n,resolve:o,reject:i},(({operation:e})=>{const n=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(n).then(o).catch(i):this.url?this.requestViaHttp(e,t).then(n).then(o).catch(i):void i(Error("GraphQLClient: config.url is required"))}))))}requestViaHttp(e,t={}){let r=this.url;const n=this.getFetchOptions(e,t.fetchOptionsOverrides);if("GET"===n.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,n).then((e=>e.ok?e.json().then((({errors:r,data:n})=>this.generateResult({graphQLErrors:r,data:G(t.responseReducer,n,e),headers:e.headers}))):e.text().then((t=>{const{status:r,statusText:n}=e;return this.generateResult({httpError:{status:r,statusText:n,body:t},headers:e.headers})})))).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 n;try{const o=this.createSubscription(e).subscribe({next:e=>{n=e},error:r,complete:()=>{o.unsubscribe(),t(n)}})}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(T.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=(n=F({},e),o={data:t(e.data||null)},P(n,Q(o)));this.saveCache(r,i),this.mutationsEmitter.emit(T.DATA_UPDATED,i)}var n,o}}function G(e,t,r){return"function"==typeof e?e(t,r):t}var N=Object.defineProperty,x=(e,t,r)=>((e,t,r)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class _{constructor(e){x(this,"fetchError"),x(this,"httpError"),x(this,"graphQLErrors"),this.fetchError=e.fetchError,this.httpError=e.httpError,this.graphQLErrors=e.graphQLErrors}}var H=Object.defineProperty,U=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,W=(e,t,r)=>J(e,"symbol"!=typeof t?t+"":t,r);function z(e){return e instanceof Error?{data:null,errors:[e]}:Array.isArray(e)?function(e){const t=Array(e.length),r=[];for(const[n,o]of e.entries()){const e=z(o);t[n]=e.data,null!=e.errors&&r.push(...e.errors)}return{data:t,errors:r}}(e):function(e){return e===Object(e)}(e)?function(e){const t={},r=[];for(const[n,o]of Object.entries(e)){const e=z(o);t[n]=e.data,null!=e.errors&&r.push(...e.errors)}return{data:t,errors:r}}(e):{data:e,errors:null}}var $=Object.prototype.hasOwnProperty;function X(e,t,r){for(r of e.keys())if(Y(r,t))return r}function Y(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--&&Y(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=X(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=X(t,o)))return!1;if(!Y(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($.call(e,r)&&++n&&!$.call(t,r))return!1;if(!(r in t)||!Y(e[r],t[r]))return!1}return Object.keys(t).length===n}}return e!=e&&t!=t}function Z(e){var t=s.useRef(e),r=s.useRef(0);return Y(e,t.current)||(t.current=e,r.current+=1),s.useMemo((function(){return t.current}),[r.current])}var ee=Object.defineProperty,te=Object.defineProperties,re=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,oe=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable,se=(e,t,r)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ae=(e,t)=>{for(var r in t||(t={}))oe.call(t,r)&&se(e,r,t[r]);if(ne)for(var r of ne(t))ie.call(t,r)&&se(e,r,t[r]);return e},ue=(e,t)=>te(e,re(t));const ce="RESET_STATE",le="LOADING",fe="CACHE_HIT",he="REQUEST_RESULT",pe="DATA_UPDATED";function de(e,t){switch(t.type){case ce:return e.loading?e:t.initialState;case le:return e.error?ue(ae({},t.initialState),{data:e.data,loading:!0}):e.loading?e:ue(ae({},e),{loading:!0});case pe:return ue(ae({},e),{data:t.result.data});case fe:return e.cacheHit&&!t.resetState?e:ue(ae({},t.result),{cacheHit:!0,loading:!1});case he:return ue(ae({},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 ye(e,t={}){var r;const n=j(e),o=null!=(r=t.operationName)?r:function(e){var t,r;let n;if("string"!=typeof e){const o=e.definitions.filter((e=>e.kind===E));1===o.length&&(n=null==(r=null==(t=o[0])?void 0:t.name)?void 0:r.value)}return n}(e),s=i.default.useContext(u),a=t.client||s;if(null==a)throw Error("A client must be provided in order to use the useClientRequest hook.");const c=i.default.useRef(!0),l=i.default.useRef(null),f={query:n,variables:t.variables,operationName:o,persisted:t.persisted};(t.persisted||a.useGETForQueries&&!t.isMutation)&&(t.fetchOptionsOverrides=ue(ae({},t.fetchOptionsOverrides),{method:"GET"}));const h=a.getCacheKey(f,t),p=t.isMutation||t.isManual||t.skip,d=!t.skipCache&&a.cache&&h?a.cache.get(h):null,y=ue(ae({},d),{cacheHit:!!d,loading:!p&&!d}),[b,v]=i.default.useReducer(de,y),m=JSON.stringify(h);i.default.useEffect((()=>{t.updateData||v({type:ce,initialState:y})}),[m]),i.default.useEffect((()=>(c.current=!0,()=>{c.current=!1})),[]);const g=i.default.useCallback((e=>{const r=ae(ae({},t),e),o=ue(ae({},f),{variables:r.variables,operationName:r.operationName});if(!c.current)return Promise.resolve({error:{fetchError:Error("fetchData should not be called after hook unmounted")},loading:!1,cacheHit:!1});const i=a.getCacheKey(o,r);l.current=i;const s=r.skipCache?null:a.getCache(i);return s?(v({type:fe,result:s,resetState:m!==JSON.stringify(b.cacheKey)}),Promise.resolve(s)):(v({type:le,initialState:y}),a.request(o,r).then((e=>{if(r.updateData&&"function"!=typeof r.updateData)throw Error("options.updateData must be a function");const s=ae({},e);if(r.useCache&&(s.useCache=!0,s.cacheKey=i,a.ssrMode)){const e={error:s.error,data:r.updateData?r.updateData(b.data,s.data):s.data};a.saveCache(i,e)}if(c.current&&i===l.current&&v({type:he,updateData:r.updateData,result:s}),t.isMutation&&a.mutationsEmitter.emit(n,ue(ae({},o),{mutation:n,result:s})),!(null==e?void 0:e.error)&&r.onSuccess){if("function"!=typeof r.onSuccess)throw Error("options.onSuccess must be a function");r.onSuccess(e,o.variables)}return e})))}),Z([a,t,f]));i.default.useEffect((()=>{b.useCache&&!a.ssrMode&&a.saveCache(b.cacheKey,b)}),[a,b]);return i.default.useEffect((()=>{const e=(e,t)=>{v({type:t,result:e})},t=t=>e(t,he),r=t=>e(t,pe),n=a.mutationsEmitter;return n.on(T.DATA_INVALIDATED,t),n.on(T.DATA_UPDATED,r),()=>{n&&(n.removeListener(T.DATA_INVALIDATED,t),n.removeListener(T.DATA_UPDATED,r))}}),[]),[g,b,(e={})=>v({type:ce,initialState:ae(ae({},y),e)})]}var be=Object.defineProperty,ve=Object.defineProperties,me=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,Ee=Object.prototype.hasOwnProperty,Oe=Object.prototype.propertyIsEnumerable,De=(e,t,r)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ce=(e,t)=>{for(var r in t||(t={}))Ee.call(t,r)&&De(e,r,t[r]);if(ge)for(var r of ge(t))Oe.call(t,r)&&De(e,r,t[r]);return e};const we={useCache:!0,skip:!1,throwErrors:!1};var Se=Object.defineProperty,Ae=Object.getOwnPropertySymbols,je=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,Le=(e,t,r)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Pe=Object.defineProperty,Qe=Object.getOwnPropertySymbols,qe=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,Re=(e,t,r)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;e.ClientContext=u,e.GraphQLClient=V,e.LocalGraphQLClient=class extends V{constructor(e){if(super(((e,t)=>{for(var r in t||(t={}))K.call(t,r)&&J(e,r,t[r]);if(U)for(var r of U(t))B.call(t,r)&&J(e,r,t[r]);return e})({url:"http://localhost"},e)),W(this,"localQueries"),W(this,"requestDelayMs"),this.localQueries=e.localQueries,this.requestDelayMs=e.requestDelayMs||0,!this.localQueries)throw Error("LocalGraphQLClient: `localQueries` object required in the constructor options")}verifyConfig(){}requestViaHttp(e,t={}){return(r=this.requestDelayMs,new Promise((e=>{setTimeout(e,r)}))).then((()=>{if(!e.query||!this.localQueries[e.query])throw Error("LocalGraphQLClient: no query match for: "+e.query);const r=this.localQueries[e.query](e.variables,e.operationName);return G(t.responseReducer,r,new Response)}));var r}request(e,t){return super.request(e,t).then((e=>{if(e instanceof _)return{error:e};const{data:t,errors:r}=z(e);return r&&r.length>0?{data:t,error:new _({graphQLErrors:r})}:{data:t}}))}},e.LocalGraphQLError=_,e.useClientRequest=ye,e.useManualQuery=(e,t={})=>ye(e,((e,t)=>{for(var r in t||(t={}))qe.call(t,r)&&Re(e,r,t[r]);if(Qe)for(var r of Qe(t))Me.call(t,r)&&Re(e,r,t[r]);return e})({useCache:!0,isManual:!0},t)),e.useMutation=(e,t={})=>ye(e,((e,t)=>{for(var r in t||(t={}))je.call(t,r)&&Le(e,r,t[r]);if(Ae)for(var r of Ae(t))Te.call(t,r)&&Le(e,r,t[r]);return e})({isMutation:!0},t)),e.useQuery=function(e,t={}){const r=Ce(Ce({},we),t),n=i.default.useContext(u),o=t.client||n,[s,a]=i.default.useState(!1),[c,l]=ye(e,r);if(!o)throw Error("useQuery() requires a client to be passed in the options or as a context value");if(o.ssrMode&&!1!==t.ssr&&!s&&!t.skipCache&&!t.skip){if(!l.data&&!l.error){const e=c();o.ssrPromises.push(e)}a(!0)}const f=((e,t)=>{var r={};for(var n in e)Ee.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&ge)for(var n of ge(e))0>t.indexOf(n)&&Oe.call(e,n)&&(r[n]=e[n]);return r})(r,["client"]),h=JSON.stringify(f);i.default.useEffect((()=>{r.skip||c()}),[e,h]),i.default.useEffect((()=>{if(l.error&&r.throwErrors)throw l.error}),[l.error,r.throwErrors]);const p=i.default.useCallback(((e={})=>c(Ce({skipCache:!0,updateData:(e,t)=>t},e))),[c]);return i.default.useEffect((function(){const e=function(e){if(!e)return{};const t={};return(Array.isArray(e)?e:[e]).forEach((e=>{var r;if(null!=e)if("string"==typeof e)t[e]={};else if("object"==typeof(r=e)&&null!=r&&"mutation"in r){const{filter:r,mutation:n,refetchOnMutationError:o=!0}=e;t[n]={filter:r,refetchOnMutationError:o}}else(function(e){return"object"==typeof e&&null!=e&&"kind"in e})(e)&&(t[j(e)]={})})),t}(t.refetchAfterMutations),r=Object.keys(e),n=({mutation:t,variables:r,result:n})=>{const{filter:o,refetchOnMutationError:i}=e[t];(!o||r&&o(r))&&(i||!n.error)&&p()};return r.forEach((e=>{o.mutationsEmitter.on(e,n)})),()=>{r.forEach((e=>{o.mutationsEmitter.removeListener(e,n)}))}}),[t.refetchAfterMutations,p,o.mutationsEmitter]),d=Ce({},l),ve(d,me({refetch:p}));var d},e.useQueryClient=function(){return t.useContext(u)},e.useSubscription=function(e,r){const n=t.useRef(r);n.current=r;const o=t.useContext(u),i=e.client||o;if(!i)throw Error("useSubscription() requires a client to be passed in the options or as a context value");!function(e,t){s.useEffect(e,Z(t))}((()=>{if(e.skip)return;const t=i.createSubscription({query:e.query,variables:e.variables}).subscribe({next:e=>{n.current(e)},error:e=>{n.current({errors:e})},complete:()=>{t.unsubscribe()}});return()=>{t.unsubscribe()}}),[e.query,e.variables,e.skip])},Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -966,2 +966,5 @@ import React, { useContext, useRef } from 'react';

useDeepCompareEffect(() => {
if (options.skip) {
return;
}
const request = {

@@ -986,3 +989,3 @@ query: options.query,

};
}, [options.query, options.variables]);
}, [options.query, options.variables, options.skip]);
}

@@ -989,0 +992,0 @@

@@ -976,2 +976,5 @@ 'use strict';

useDeepCompareEffect__default["default"](() => {
if (options.skip) {
return;
}
const request = {

@@ -996,3 +999,3 @@ query: options.query,

};
}, [options.query, options.variables]);
}, [options.query, options.variables, options.skip]);
}

@@ -999,0 +1002,0 @@

import { UseSubscriptionOperation } from './types/common-types';
declare function useSubscription<ResponseData = any, Variables extends object = object, TGraphQLError = object>(options: UseSubscriptionOperation<Variables>, callback: (response: {
declare function useSubscription<ResponseData = any, Variables extends object = object, TGraphQLError = object>(options: UseSubscriptionOperation<Variables> & {
skip?: boolean;
}, callback: (response: {
data?: ResponseData;

@@ -4,0 +6,0 @@ errors?: TGraphQLError[];

{
"name": "graphql-hooks",
"version": "8.1.0",
"version": "8.2.0",
"description": "Graphql Hooks",

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

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

@@ -427,2 +427,3 @@ # graphql-hooks

- `client`: GraphQLClient - If a GraphQLClient is explicitly passed as an option, then it will be used instead of the client from the `ClientContext`.
- `skip`: Boolean (optional) - If true, the subscription will not be created.
- `callback`: Function - This will be invoked when the subscription receives an event from your GraphQL server - it will receive an object with the typical GraphQL response of `{ data: <your result>, errors?: [Error] }`

@@ -1501,1 +1502,3 @@

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
[![banner](https://raw.githubusercontent.com/nearform/.github/refs/heads/master/assets/os-banner-green.svg)](https://www.nearform.com/contact/?utm_source=open-source&utm_medium=banner&utm_campaign=os-project-pages)

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