Socket
Socket
Sign inDemoInstall

graphql-hooks

Package Overview
Dependencies
23
Maintainers
5
Versions
85
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.3.2 to 6.4.0

lib/GraphQLClient-719063e6.js

14

dist/graphql-hooks.js

@@ -34,2 +34,6 @@ (function (global, factory) {

function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
/**

@@ -81,3 +85,3 @@ * Used to mark a

var ReactNativeFile = ReactNativeFile_1;
const ReactNativeFile = ReactNativeFile_1;

@@ -111,5 +115,5 @@ /**

};
var isExtractableFile$1 = isExtractableFile;
var isExtractableFile$1 = /*@__PURE__*/getDefaultExportFromCjs(isExtractableFile);
var defaultIsExtractableFile = isExtractableFile;
const defaultIsExtractableFile = isExtractableFile;

@@ -236,3 +240,3 @@ /**

};
var extractFiles$1 = extractFiles;
var extractFiles$1 = /*@__PURE__*/getDefaultExportFromCjs(extractFiles);

@@ -294,3 +298,3 @@ var canUseDOM = (function () {

}
_this.run = function (stack) {
_this.run = /* @__PURE__ */function (stack) {
return function (opts, next) {

@@ -297,0 +301,0 @@ stack(opts, function () {

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

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

@@ -64,3 +64,3 @@ import React, { useContext, useRef } from 'react';

}
_this.run = function (stack) {
_this.run = /* @__PURE__ */function (stack) {
return function (opts, next) {

@@ -67,0 +67,0 @@ stack(opts, function () {

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

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

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

@@ -74,3 +74,3 @@ 'use strict';

}
_this.run = function (stack) {
_this.run = /* @__PURE__ */function (stack) {
return function (opts, next) {

@@ -77,0 +77,0 @@ stack(opts, function () {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

{
"name": "graphql-hooks",
"version": "6.3.2",
"version": "6.4.0",
"description": "Graphql Hooks",

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

"dependencies": {
"@aws-crypto/sha256-browser": "^4.0.0",
"@aws-crypto/sha256-browser": "^5.2.0",
"buffer": "^6.0.3",

@@ -51,3 +51,3 @@ "events": "^3.3.0",

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

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

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

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

- [Testing and mocking](#testing-and-mocking)
- [Typescript Support](#typescript-support)
- [Other]

@@ -623,3 +624,3 @@ - [Request interceptors](#request-interceptors)

We can have a query to automatically refetch when any mutation from a provided list execute.
We can have a query to automatically refetch when any mutation from a provided list is executed.
In the following example we are refetching a list of posts for a given user.

@@ -690,3 +691,3 @@

### By overring the old state in the cache without re-fetching data
### By overriding the old state in the cache without re-fetching data

@@ -819,5 +820,5 @@ ```js

You can have access the to the graphql-hooks client context by using the React's new context API. `ClientContext` is actually the result of `React.createContext()`.
You can have access to the graphql-hooks client context by using React's new context API. `ClientContext` is actually the result of `React.createContext()`.
**Login example**
**Login Example**

@@ -876,3 +877,3 @@ ```jsx

Then we request the token from the server by performing the `loginUser` mutation.
In the case the login is success we set the token to the client's header (`client.setHeader`), otherwise we need to handle the error.
In the case the login is successful we set the token to the client's header (`client.setHeader`), otherwise we need to handle the error.
For more information about graphql-hooks clientContext refer to [GraphQLClient](#GraphQLClient) section.

@@ -963,4 +964,4 @@

- **Fetch Policies**: See [#75](https://github.com/nearform/graphql-hooks/issues/75) for more info
- `cache-first`: This the default behaviour of `graphql-hooks`
- `cache-and-network`: The refetch function provides this behaviour it will set loading: true, but the old data will be still set until the fetch resolves.
- `cache-first`: This is the default behaviour of `graphql-hooks`
- `cache-and-network`: The refetch function provides this behavior it will set loading: true, but the old data will be still set until the fetch resolves.
- `network-only` ➡️ `useQuery(QUERY, { skipCache: true })`

@@ -1212,3 +1213,3 @@ - `cache-only`: Not supported

Using this allows to easily render a component using the `LocalGraphQLClient` with local queries when writing tests:
Using this allows us to easily render a component using the `LocalGraphQLClient` with local queries when writing tests:

@@ -1325,2 +1326,50 @@ ```js

## Typescript Support
All client methods support the ability to provide type information for response data, query variables and error responses.
```typescript
import { useQuery } from 'graphql-hooks'
type User = {
id: string
name: string
}
type CustomError = {
message: string
extensions?: Record<string, any>
}
const HOMEPAGE_QUERY = `query HomePage($limit: Int) {
users(limit: $limit) {
id
name
}
}`
function MyComponent() {
const { loading, error, data } = useQuery<
User,
{ limit: number },
CustomError
>(HOMEPAGE_QUERY, {
variables: {
limit: 10
}
})
if (loading) return 'Loading...'
if (error) return 'Something Bad Happened'
return (
<ul>
{data.users.map(({ id, name }) => (
<li key={id}>{name}</li>
))}
</ul>
)
}
```
## Community

@@ -1380,2 +1429,2 @@

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc