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
5
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.0.0 to 8.0.1

13

dist/graphql-hooks.js

@@ -650,6 +650,7 @@ (function (global, factory) {

graphQLErrors,
data
data,
headers
}) {
const errorFound = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError);
return !errorFound ? { data } : { data, error: { fetchError, httpError, graphQLErrors } };
return !errorFound ? { data, headers } : { data, error: { fetchError, httpError, graphQLErrors }, headers };
}

@@ -770,3 +771,4 @@ getCacheKey(operation, options = {}) {

body
}
},
headers: response.headers
});

@@ -780,4 +782,5 @@ });

// enrich data with responseReducer if defined
typeof options.responseReducer === "function" && options.responseReducer(data, response) || data
)
typeof options.responseReducer === "function" ? options.responseReducer(data, response) : data
),
headers: response.headers
});

@@ -784,0 +787,0 @@ });

@@ -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}},E=c(d);const y=e=>h(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe||null!==e&&"object"==typeof e&&"function"==typeof e.stream;function b(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 b(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)?b(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 v=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}(),g={NAME:"Name",DOCUMENT:"Document",OPERATION_DEFINITION:"OperationDefinition",VARIABLE_DEFINITION:"VariableDefinition",SELECTION_SET:"SelectionSet",FIELD:"Field",ARGUMENT:"Argument",FRAGMENT_SPREAD:"FragmentSpread",INLINE_FRAGMENT:"InlineFragment",FRAGMENT_DEFINITION:"FragmentDefinition",VARIABLE:"Variable",INT:"IntValue",FLOAT:"FloatValue",STRING:"StringValue",BOOLEAN:"BooleanValue",NULL:"NullValue",ENUM:"EnumValue",LIST:"ListValue",OBJECT:"ObjectValue",OBJECT_FIELD:"ObjectField",DIRECTIVE:"Directive",NAMED_TYPE:"NamedType",LIST_TYPE:"ListType",NON_NULL_TYPE:"NonNullType"},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||{}),T=function(e){return e[e.Spread=1]="Spread",e[e.Name=2]="Name",e}(T||{});function D(e,t,r){for(var n="",o=0;e.length>o;o++)o&&(n+=t),n+=r(e[o]);return n}var A="\n",S={OperationDefinition(e){var t=e.operation;return e.name&&(t+=" "+e.name.value),e.variableDefinitions&&e.variableDefinitions.length&&(e.name||(t+=" "),t+="("+D(e.variableDefinitions,", ",S.VariableDefinition)+")"),e.directives&&e.directives.length&&(t+=" "+D(e.directives," ",S.Directive)),"query"!==t?t+" "+S.SelectionSet(e.selectionSet):S.SelectionSet(e.selectionSet)},VariableDefinition(e){var t=S.Variable(e.variable)+": "+C(e.type);return e.defaultValue&&(t+=" = "+C(e.defaultValue)),e.directives&&e.directives.length&&(t+=" "+D(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=D(e.arguments,", ",S.Argument);t+=t.length+r.length+2>80?"("+(A+=" ")+D(e.arguments,A,S.Argument)+(A=A.slice(0,-2))+")":"("+r+")"}return e.directives&&e.directives.length&&(t+=" "+D(e.directives," ",S.Directive)),e.selectionSet&&(t+=" "+S.SelectionSet(e.selectionSet)),t},StringValue:e=>e.block?function(e){return'"""\n'+e.replace(/"""/g,'\\"""')+'\n"""'}(e.value).replace(/\n/g,A):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=>"["+D(e.values,", ",C)+"]",ObjectValue:e=>"{"+D(e.fields,", ",S.ObjectField)+"}",ObjectField:e=>e.name.value+": "+C(e.value),Document:e=>e.definitions&&e.definitions.length?D(e.definitions,"\n\n",C):"",SelectionSet:e=>"{"+(A+=" ")+D(e.selections,A,C)+(A=A.slice(0,-2))+"}",Argument:e=>e.name.value+": "+C(e.value),FragmentSpread(e){var t="..."+e.name.value;return e.directives&&e.directives.length&&(t+=" "+D(e.directives," ",S.Directive)),t},InlineFragment(e){var t="...";return e.typeCondition&&(t+=" on "+e.typeCondition.name.value),e.directives&&e.directives.length&&(t+=" "+D(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+=" "+D(e.directives," ",S.Directive)),t+" "+S.SelectionSet(e.selectionSet)},Directive(e){var t="@"+e.name.value;return e.arguments&&e.arguments.length&&(t+="("+D(e.arguments,", ",S.Argument)+")"),t},NamedType:e=>e.name.value,ListType:e=>"["+C(e.type)+"]",NonNullType:e=>C(e.type)+"!"},C=e=>S[e.kind](e);function w(e){return"string"==typeof e?e:function(e){return A="\n",S[e.kind]?S[e.kind](e):""}(e)}var L=(e=>(e.DATA_INVALIDATED="DATA_INVALIDATED",e.DATA_UPDATED="DATA_UPDATED",e))(L||{}),j=Object.defineProperty,I=Object.defineProperties,N=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,F=(e,t,r)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,_=(e,t)=>{for(var r in t||(t={}))R.call(t,r)&&F(e,r,t[r]);if(P)for(var r of P(t))Q.call(t,r)&&F(e,r,t[r]);return e},M=(e,t,r)=>(F(e,"symbol"!=typeof t?t+"":t,r),r);class V{constructor(e){if(M(this,"url"),M(this,"ssrPromises"),M(this,"FormData"),M(this,"fetch"),M(this,"fetchOptions"),M(this,"logErrors"),M(this,"useGETForQueries"),M(this,"middleware"),M(this,"mutationsEmitter"),M(this,"cache"),M(this,"headers"),M(this,"ssrMode"),M(this,"subscriptionClient"),M(this,"fullWsTransport"),M(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 v(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}){return!!(r&&r.length>0||e||t)?{data:n,error:{fetchError:e,httpError:t,graphQLErrors:r}}:{data:n}}getCacheKey(e,t={}){return{operation:e,fetchOptions:_(_({},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=_(_({method:"POST",headers:_({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;const{clone:n,files:o}=E(e,"",y),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){const t=Object.entries(e).filter((([,e])=>!!e)).map((([e,t])=>("variables"!==e&&"extensions"!==e||(t=JSON.stringify(t)),`${e}=${encodeURIComponent(t)}`))).join("&");r=r+"?"+t}return this.fetch(r,n).then((e=>e.ok?e.json().then((({errors:r,data:n})=>this.generateResult({graphQLErrors:r,data:"function"==typeof t.responseReducer&&t.responseReducer(n,e)||n}))):e.text().then((t=>{const{status:r,statusText:n}=e;return this.generateResult({httpError:{status:r,statusText:n,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 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(L.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=_({},e),o={data:t(e.data||null)},I(n,N(o)));this.saveCache(r,i),this.mutationsEmitter.emit(L.DATA_UPDATED,i)}var n,o}}var q=Object.defineProperty,G=(e,t,r)=>(((e,t,r)=>{t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class k{constructor(e){G(this,"fetchError"),G(this,"httpError"),G(this,"graphQLErrors"),this.fetchError=e.fetchError,this.httpError=e.httpError,this.graphQLErrors=e.graphQLErrors}}var U=Object.defineProperty,x=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,K=(e,t,r)=>(J(e,"symbol"!=typeof t?t+"":t,r),r);function W(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}}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)?W(e):{data:e,errors:null}}var $=Object.prototype.hasOwnProperty;function Y(e,t,r){for(r of e.keys())if(X(r,t))return r}function X(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--&&X(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=Y(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=Y(t,o)))return!1;if(!X(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)||!X(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 X(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:"RESET_STATE",LOADING:"LOADING",CACHE_HIT:"CACHE_HIT",REQUEST_RESULT:"REQUEST_RESULT",DATA_UPDATED:"DATA_UPDATED"};function le(e,t){switch(t.type){case ce.RESET_STATE:return e.loading?e:t.initialState;case ce.LOADING:return e.error?ue(ae({},t.initialState),{data:e.data,loading:!0}):e.loading?e:ue(ae({},e),{loading:!0});case ce.DATA_UPDATED:return ue(ae({},e),{data:t.result.data});case ce.CACHE_HIT:return e.cacheHit&&!t.resetState?e:ue(ae({},t.result),{cacheHit:!0,loading:!1});case ce.REQUEST_RESULT: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 fe(e,t={}){var r;const n=w(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===g.OPERATION_DEFINITION));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,E=ue(ae({},d),{cacheHit:!!d,loading:!p&&!d}),[y,b]=i.default.useReducer(le,E),m=JSON.stringify(h);i.default.useEffect((()=>{t.updateData||b({type:ce.RESET_STATE,initialState:E})}),[m]),i.default.useEffect((()=>(c.current=!0,()=>{c.current=!1})),[]);const v=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?(b({type:ce.CACHE_HIT,result:s,resetState:m!==JSON.stringify(y.cacheKey)}),Promise.resolve(s)):(b({type:ce.LOADING,initialState:E}),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(y.data,s.data):s.data};a.saveCache(i,e)}if(c.current&&i===l.current&&b({type:ce.REQUEST_RESULT,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((()=>{y.useCache&&!a.ssrMode&&a.saveCache(y.cacheKey,y)}),[a,y]);return i.default.useEffect((()=>{const e=(e,t)=>{b({type:t,result:e})},t=t=>e(t,ce.REQUEST_RESULT),r=t=>e(t,ce.DATA_UPDATED),n=a.mutationsEmitter;return n.on(L.DATA_INVALIDATED,t),n.on(L.DATA_UPDATED,r),()=>{n&&(n.removeListener(L.DATA_INVALIDATED,t),n.removeListener(L.DATA_UPDATED,r))}}),[]),[v,y,(e={})=>b({type:ce.RESET_STATE,initialState:ae(ae({},E),e)})]}var he=Object.defineProperty,pe=Object.defineProperties,de=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertySymbols,ye=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable,me=(e,t,r)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ve=(e,t)=>{for(var r in t||(t={}))ye.call(t,r)&&me(e,r,t[r]);if(Ee)for(var r of Ee(t))be.call(t,r)&&me(e,r,t[r]);return e};const ge={useCache:!0,skip:!1,throwErrors:!1};var Oe=Object.defineProperty,Te=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,Se=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ce=Object.defineProperty,we=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Ie=(e,t,r)=>t in e?Ce(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={}))H.call(t,r)&&J(e,r,t[r]);if(x)for(var r of x(t))B.call(t,r)&&J(e,r,t[r]);return e})({url:""},e)),K(this,"localQueries"),K(this,"requestDelayMs"),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 k)return{error:e};const{data:t,errors:r}=W(e);return r.length>0?{data:t,error:new k({graphQLErrors:r})}:{data:t}}));var t}},e.LocalGraphQLError=k,e.useClientRequest=fe,e.useManualQuery=(e,t={})=>fe(e,((e,t)=>{for(var r in t||(t={}))Le.call(t,r)&&Ie(e,r,t[r]);if(we)for(var r of we(t))je.call(t,r)&&Ie(e,r,t[r]);return e})({useCache:!0,isManual:!0},t)),e.useMutation=(e,t={})=>fe(e,((e,t)=>{for(var r in t||(t={}))De.call(t,r)&&Se(e,r,t[r]);if(Te)for(var r of Te(t))Ae.call(t,r)&&Se(e,r,t[r]);return e})({isMutation:!0},t)),e.useQuery=function(e,t={}){const r=ve(ve({},ge),t),n=i.default.useContext(u),o=t.client||n,[s,a]=i.default.useState(!1),[c,l]=fe(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)ye.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&Ee)for(var n of Ee(e))0>t.indexOf(n)&&be.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(ve({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[w(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=ve({},l),pe(d,de({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}},E=c(d);const y=e=>h(e)||null!==e&&"object"==typeof e&&"function"==typeof e.pipe||null!==e&&"object"==typeof e&&"function"==typeof e.stream;function b(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 b(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)?b(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 v=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}(),g={NAME:"Name",DOCUMENT:"Document",OPERATION_DEFINITION:"OperationDefinition",VARIABLE_DEFINITION:"VariableDefinition",SELECTION_SET:"SelectionSet",FIELD:"Field",ARGUMENT:"Argument",FRAGMENT_SPREAD:"FragmentSpread",INLINE_FRAGMENT:"InlineFragment",FRAGMENT_DEFINITION:"FragmentDefinition",VARIABLE:"Variable",INT:"IntValue",FLOAT:"FloatValue",STRING:"StringValue",BOOLEAN:"BooleanValue",NULL:"NullValue",ENUM:"EnumValue",LIST:"ListValue",OBJECT:"ObjectValue",OBJECT_FIELD:"ObjectField",DIRECTIVE:"Directive",NAMED_TYPE:"NamedType",LIST_TYPE:"ListType",NON_NULL_TYPE:"NonNullType"},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||{}),T=function(e){return e[e.Spread=1]="Spread",e[e.Name=2]="Name",e}(T||{});function D(e,t,r){for(var n="",o=0;e.length>o;o++)o&&(n+=t),n+=r(e[o]);return n}var A="\n",S={OperationDefinition(e){var t=e.operation;return e.name&&(t+=" "+e.name.value),e.variableDefinitions&&e.variableDefinitions.length&&(e.name||(t+=" "),t+="("+D(e.variableDefinitions,", ",S.VariableDefinition)+")"),e.directives&&e.directives.length&&(t+=" "+D(e.directives," ",S.Directive)),"query"!==t?t+" "+S.SelectionSet(e.selectionSet):S.SelectionSet(e.selectionSet)},VariableDefinition(e){var t=S.Variable(e.variable)+": "+C(e.type);return e.defaultValue&&(t+=" = "+C(e.defaultValue)),e.directives&&e.directives.length&&(t+=" "+D(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=D(e.arguments,", ",S.Argument);t+=t.length+r.length+2>80?"("+(A+=" ")+D(e.arguments,A,S.Argument)+(A=A.slice(0,-2))+")":"("+r+")"}return e.directives&&e.directives.length&&(t+=" "+D(e.directives," ",S.Directive)),e.selectionSet&&(t+=" "+S.SelectionSet(e.selectionSet)),t},StringValue:e=>e.block?function(e){return'"""\n'+e.replace(/"""/g,'\\"""')+'\n"""'}(e.value).replace(/\n/g,A):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=>"["+D(e.values,", ",C)+"]",ObjectValue:e=>"{"+D(e.fields,", ",S.ObjectField)+"}",ObjectField:e=>e.name.value+": "+C(e.value),Document:e=>e.definitions&&e.definitions.length?D(e.definitions,"\n\n",C):"",SelectionSet:e=>"{"+(A+=" ")+D(e.selections,A,C)+(A=A.slice(0,-2))+"}",Argument:e=>e.name.value+": "+C(e.value),FragmentSpread(e){var t="..."+e.name.value;return e.directives&&e.directives.length&&(t+=" "+D(e.directives," ",S.Directive)),t},InlineFragment(e){var t="...";return e.typeCondition&&(t+=" on "+e.typeCondition.name.value),e.directives&&e.directives.length&&(t+=" "+D(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+=" "+D(e.directives," ",S.Directive)),t+" "+S.SelectionSet(e.selectionSet)},Directive(e){var t="@"+e.name.value;return e.arguments&&e.arguments.length&&(t+="("+D(e.arguments,", ",S.Argument)+")"),t},NamedType:e=>e.name.value,ListType:e=>"["+C(e.type)+"]",NonNullType:e=>C(e.type)+"!"},C=e=>S[e.kind](e);function w(e){return"string"==typeof e?e:function(e){return A="\n",S[e.kind]?S[e.kind](e):""}(e)}var L=(e=>(e.DATA_INVALIDATED="DATA_INVALIDATED",e.DATA_UPDATED="DATA_UPDATED",e))(L||{}),j=Object.defineProperty,I=Object.defineProperties,N=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,F=(e,t,r)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,_=(e,t)=>{for(var r in t||(t={}))R.call(t,r)&&F(e,r,t[r]);if(P)for(var r of P(t))Q.call(t,r)&&F(e,r,t[r]);return e},M=(e,t,r)=>(F(e,"symbol"!=typeof t?t+"":t,r),r);class V{constructor(e){if(M(this,"url"),M(this,"ssrPromises"),M(this,"FormData"),M(this,"fetch"),M(this,"fetchOptions"),M(this,"logErrors"),M(this,"useGETForQueries"),M(this,"middleware"),M(this,"mutationsEmitter"),M(this,"cache"),M(this,"headers"),M(this,"ssrMode"),M(this,"subscriptionClient"),M(this,"fullWsTransport"),M(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 v(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:_(_({},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=_(_({method:"POST",headers:_({},this.headers)},this.fetchOptions),t);if("GET"===r.method)return r;const{clone:n,files:o}=E(e,"",y),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){const t=Object.entries(e).filter((([,e])=>!!e)).map((([e,t])=>("variables"!==e&&"extensions"!==e||(t=JSON.stringify(t)),`${e}=${encodeURIComponent(t)}`))).join("&");r=r+"?"+t}return this.fetch(r,n).then((e=>e.ok?e.json().then((({errors:r,data:n})=>this.generateResult({graphQLErrors:r,data:"function"==typeof t.responseReducer?t.responseReducer(n,e):n,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(L.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=_({},e),o={data:t(e.data||null)},I(n,N(o)));this.saveCache(r,i),this.mutationsEmitter.emit(L.DATA_UPDATED,i)}var n,o}}var q=Object.defineProperty,G=(e,t,r)=>(((e,t,r)=>{t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class k{constructor(e){G(this,"fetchError"),G(this,"httpError"),G(this,"graphQLErrors"),this.fetchError=e.fetchError,this.httpError=e.httpError,this.graphQLErrors=e.graphQLErrors}}var U=Object.defineProperty,x=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,K=(e,t,r)=>(J(e,"symbol"!=typeof t?t+"":t,r),r);function W(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}}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)?W(e):{data:e,errors:null}}var $=Object.prototype.hasOwnProperty;function Y(e,t,r){for(r of e.keys())if(X(r,t))return r}function X(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--&&X(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=Y(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=Y(t,o)))return!1;if(!X(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)||!X(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 X(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:"RESET_STATE",LOADING:"LOADING",CACHE_HIT:"CACHE_HIT",REQUEST_RESULT:"REQUEST_RESULT",DATA_UPDATED:"DATA_UPDATED"};function le(e,t){switch(t.type){case ce.RESET_STATE:return e.loading?e:t.initialState;case ce.LOADING:return e.error?ue(ae({},t.initialState),{data:e.data,loading:!0}):e.loading?e:ue(ae({},e),{loading:!0});case ce.DATA_UPDATED:return ue(ae({},e),{data:t.result.data});case ce.CACHE_HIT:return e.cacheHit&&!t.resetState?e:ue(ae({},t.result),{cacheHit:!0,loading:!1});case ce.REQUEST_RESULT: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 fe(e,t={}){var r;const n=w(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===g.OPERATION_DEFINITION));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,E=ue(ae({},d),{cacheHit:!!d,loading:!p&&!d}),[y,b]=i.default.useReducer(le,E),m=JSON.stringify(h);i.default.useEffect((()=>{t.updateData||b({type:ce.RESET_STATE,initialState:E})}),[m]),i.default.useEffect((()=>(c.current=!0,()=>{c.current=!1})),[]);const v=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?(b({type:ce.CACHE_HIT,result:s,resetState:m!==JSON.stringify(y.cacheKey)}),Promise.resolve(s)):(b({type:ce.LOADING,initialState:E}),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(y.data,s.data):s.data};a.saveCache(i,e)}if(c.current&&i===l.current&&b({type:ce.REQUEST_RESULT,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((()=>{y.useCache&&!a.ssrMode&&a.saveCache(y.cacheKey,y)}),[a,y]);return i.default.useEffect((()=>{const e=(e,t)=>{b({type:t,result:e})},t=t=>e(t,ce.REQUEST_RESULT),r=t=>e(t,ce.DATA_UPDATED),n=a.mutationsEmitter;return n.on(L.DATA_INVALIDATED,t),n.on(L.DATA_UPDATED,r),()=>{n&&(n.removeListener(L.DATA_INVALIDATED,t),n.removeListener(L.DATA_UPDATED,r))}}),[]),[v,y,(e={})=>b({type:ce.RESET_STATE,initialState:ae(ae({},E),e)})]}var he=Object.defineProperty,pe=Object.defineProperties,de=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertySymbols,ye=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable,me=(e,t,r)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ve=(e,t)=>{for(var r in t||(t={}))ye.call(t,r)&&me(e,r,t[r]);if(Ee)for(var r of Ee(t))be.call(t,r)&&me(e,r,t[r]);return e};const ge={useCache:!0,skip:!1,throwErrors:!1};var Oe=Object.defineProperty,Te=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,Se=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ce=Object.defineProperty,we=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Ie=(e,t,r)=>t in e?Ce(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={}))H.call(t,r)&&J(e,r,t[r]);if(x)for(var r of x(t))B.call(t,r)&&J(e,r,t[r]);return e})({url:""},e)),K(this,"localQueries"),K(this,"requestDelayMs"),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 k)return{error:e};const{data:t,errors:r}=W(e);return r.length>0?{data:t,error:new k({graphQLErrors:r})}:{data:t}}));var t}},e.LocalGraphQLError=k,e.useClientRequest=fe,e.useManualQuery=(e,t={})=>fe(e,((e,t)=>{for(var r in t||(t={}))Le.call(t,r)&&Ie(e,r,t[r]);if(we)for(var r of we(t))je.call(t,r)&&Ie(e,r,t[r]);return e})({useCache:!0,isManual:!0},t)),e.useMutation=(e,t={})=>fe(e,((e,t)=>{for(var r in t||(t={}))De.call(t,r)&&Se(e,r,t[r]);if(Te)for(var r of Te(t))Ae.call(t,r)&&Se(e,r,t[r]);return e})({isMutation:!0},t)),e.useQuery=function(e,t={}){const r=ve(ve({},ge),t),n=i.default.useContext(u),o=t.client||n,[s,a]=i.default.useState(!1),[c,l]=fe(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)ye.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&Ee)for(var n of Ee(e))0>t.indexOf(n)&&be.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(ve({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[w(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=ve({},l),pe(d,de({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})}));

@@ -251,6 +251,7 @@ import React, { useContext, useRef } from 'react';

graphQLErrors,
data
data,
headers
}) {
const errorFound = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError);
return !errorFound ? { data } : { data, error: { fetchError, httpError, graphQLErrors } };
return !errorFound ? { data, headers } : { data, error: { fetchError, httpError, graphQLErrors }, headers };
}

@@ -371,3 +372,4 @@ getCacheKey(operation, options = {}) {

body
}
},
headers: response.headers
});

@@ -381,4 +383,5 @@ });

// enrich data with responseReducer if defined
typeof options.responseReducer === "function" && options.responseReducer(data, response) || data
)
typeof options.responseReducer === "function" ? options.responseReducer(data, response) : data
),
headers: response.headers
});

@@ -385,0 +388,0 @@ });

@@ -261,6 +261,7 @@ 'use strict';

graphQLErrors,
data
data,
headers
}) {
const errorFound = !!(graphQLErrors && graphQLErrors.length > 0 || fetchError || httpError);
return !errorFound ? { data } : { data, error: { fetchError, httpError, graphQLErrors } };
return !errorFound ? { data, headers } : { data, error: { fetchError, httpError, graphQLErrors }, headers };
}

@@ -381,3 +382,4 @@ getCacheKey(operation, options = {}) {

body
}
},
headers: response.headers
});

@@ -391,4 +393,5 @@ });

// enrich data with responseReducer if defined
typeof options.responseReducer === "function" && options.responseReducer(data, response) || data
)
typeof options.responseReducer === "function" ? options.responseReducer(data, response) : data
),
headers: response.headers
});

@@ -395,0 +398,0 @@ });

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

}): void;
generateResult<ResponseData = any, TGraphQLError = object>({ fetchError, httpError, graphQLErrors, data }: GenerateResultOptions<ResponseData, TGraphQLError>): Result<ResponseData, TGraphQLError>;
generateResult<ResponseData = any, TGraphQLError = object>({ fetchError, httpError, graphQLErrors, data, headers }: GenerateResultOptions<ResponseData, TGraphQLError>): Result<ResponseData, TGraphQLError>;
getCacheKey<Variables = object>(operation: Operation, options?: UseClientRequestOptions<any, Variables>): CacheKeyObject;

@@ -38,0 +38,0 @@ getCache(cacheKey: any): object | undefined;

@@ -89,2 +89,3 @@ import { Client as GraphQLWsClient } from 'graphql-ws';

error?: APIError<TGraphQLError>;
headers?: Response['headers'];
}

@@ -101,2 +102,3 @@ export interface RequestOptions {

data?: ResponseData;
headers?: Response['headers'];
}

@@ -103,0 +105,0 @@ export interface UseClientRequestOptions<ResponseData = any, Variables = object, TGraphQLError = GraphQLResponseError> {

{
"name": "graphql-hooks",
"version": "8.0.0",
"version": "8.0.1",
"description": "Graphql Hooks",

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

"cross-env": "^7.0.3",
"formdata-node": "^4.3.2",
"formdata-node": "^6.0.3",
"graphql": "^16.8.1",

@@ -71,3 +71,3 @@ "graphql-hooks-memcache": "^3.2.0",

"homepage": "https://github.com/nearform/graphql-hooks#readme",
"gitHead": "86b65ba4cd5ef0bd78d26b6101b7338b6afd802c"
"gitHead": "0f98171e4af3e92de16fbbee45cd80af5abe20cf"
}

@@ -14,3 +14,3 @@ # graphql-hooks

- 🥇 First-class hooks API
- ⚖️ _Tiny_ bundle: only 7.6kB (2.8 gzipped)
- ⚖️ _Tiny_ bundle: only 22.9kB (7.4kB gzipped)
- 📄 Full SSR support: see [graphql-hooks-ssr](packages/graphql-hooks-ssr)

@@ -171,3 +171,3 @@ - 🔌 Plugin Caching: see [graphql-hooks-memcache](packages/graphql-hooks-memcache)

- `operation`: Object with `query`, `variables` and `operationName`
- `result`: Object containing `data` and `error` object that contains `fetchError`, `httpError` and `graphqlErrors`
- `result`: Object containing `data`, `headers` and `error` object that contains `fetchError`, `httpError` and `graphqlErrors`

@@ -275,2 +275,3 @@ ### `client` methods

- `data`: Object - the result of your GraphQL query
- `headers`: Object - response headers
- `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.

@@ -411,2 +412,3 @@ - `options`: Object - options that will be merged into the `options` that were passed into `useQuery` (see above).

- `data`: Object - the data
- `headers`: Object - response headers
- `error`: Error - the error

@@ -413,0 +415,0 @@ - `loading`: Boolean - true if it is still loading

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