Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo/react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/react-hooks - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

19

lib/data/QueryData.js

@@ -31,5 +31,11 @@ import * as tslib_1 from "tslib";

_this.obsStartPolling = function (pollInterval) {
return _this.currentObservable.query.startPolling(pollInterval);
_this.currentObservable &&
_this.currentObservable.query &&
_this.currentObservable.query.startPolling(pollInterval);
};
_this.obsStopPolling = function () { return _this.currentObservable.query.stopPolling(); };
_this.obsStopPolling = function () {
_this.currentObservable &&
_this.currentObservable.query &&
_this.currentObservable.query.stopPolling();
};
_this.obsSubscribeToMore = function (options) { return _this.currentObservable.query.subscribeToMore(options); };

@@ -184,3 +190,5 @@ _this.forceUpdate = forceUpdate;

throw error;
if (!isEqual(error, _this.previousData.error)) {
var previousResult = _this.previousData.result;
if ((previousResult && previousResult.loading) ||
!isEqual(error, _this.previousData.error)) {
_this.previousData.error = error;

@@ -255,3 +263,6 @@ _this.forceUpdate();

QueryData.prototype.handleErrorOrCompleted = function () {
var _a = this.currentObservable.query.getCurrentResult(), data = _a.data, loading = _a.loading, error = _a.error;
var obsQuery = this.currentObservable.query;
if (!obsQuery)
return;
var _a = obsQuery.getCurrentResult(), data = _a.data, loading = _a.loading, error = _a.error;
if (!loading) {

@@ -258,0 +269,0 @@ var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError;

@@ -26,4 +26,6 @@ exports.__esModule = true;

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var OperationData = function () {

@@ -126,7 +128,7 @@ function OperationData(options, context) {

_this.obsStartPolling = function (pollInterval) {
return _this.currentObservable.query.startPolling(pollInterval);
_this.currentObservable && _this.currentObservable.query && _this.currentObservable.query.startPolling(pollInterval);
};
_this.obsStopPolling = function () {
return _this.currentObservable.query.stopPolling();
_this.currentObservable && _this.currentObservable.query && _this.currentObservable.query.stopPolling();
};

@@ -324,4 +326,5 @@

if (!error.hasOwnProperty('graphQLErrors')) throw error;
var previousResult = _this.previousData.result;
if (!(0, _equality.equal)(error, _this.previousData.error)) {
if (previousResult && previousResult.loading || !(0, _equality.equal)(error, _this.previousData.error)) {
_this.previousData.error = error;

@@ -411,3 +414,6 @@

QueryData.prototype.handleErrorOrCompleted = function () {
var _a = this.currentObservable.query.getCurrentResult(),
var obsQuery = this.currentObservable.query;
if (!obsQuery) return;
var _a = obsQuery.getCurrentResult(),
data = _a.data,

@@ -519,3 +525,3 @@ loading = _a.loading,

});
}, [queryResult.loading, queryResult.networkStatus, queryResult.error, queryResult.data]);
}, lazy ? undefined : [queryResult.loading, queryResult.networkStatus, queryResult.error, queryResult.data]);
(0, _react.useEffect)(function () {

@@ -522,0 +528,0 @@ return function () {

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

exports.__esModule=!0,exports.useApolloClient=function(){var e=r.default.useContext((0,t.getApolloContext)()).client;return(0,o.invariant)(e,1),e},exports.useLazyQuery=function(t,e){return a(t,e,!0)},exports.useMutation=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useState)({called:!1,loading:!1}),u=n[0],a=n[1],p=s?(0,e.__assign)({},s,{mutation:i}):{mutation:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new c({options:p,context:o,result:u,setResult:a}));return l.current}();return h.setOptions(p),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),h.execute(u)},exports.useQuery=function(t,e){return a(t,e,!1)},exports.useSubscription=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=s?(0,e.__assign)({},s,{subscription:i}):{subscription:i},u=(0,r.useState)({loading:!n.skip,error:void 0,data:void 0}),a=u[0],c=u[1],l=(0,r.useRef)();var h=function(){l.current||(l.current=new p({options:n,context:o,setResult:c}));return l.current}();return h.setOptions(n),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),(0,r.useEffect)(function(){return h.cleanup.bind(h)},[]),h.execute(a)},exports.RenderPromises=exports.resetApolloContext=exports.ApolloProvider=exports.ApolloConsumer=void 0;var t=require("@apollo/react-common");exports.getApolloContext=t.getApolloContext,exports.ApolloConsumer=t.ApolloConsumer,exports.ApolloProvider=t.ApolloProvider,exports.resetApolloContext=t.resetApolloContext;var e=require("tslib"),r=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(t,r):{};i.get||i.set?Object.defineProperty(e,r,i):e[r]=t[r]}return e.default=t,e}(require("react")),i=require("apollo-client"),s=require("@wry/equality"),o=require("ts-invariant");var n=function(){function e(t,e){this.isMounted=!1,this.previousOptions={},this.context={},this.options={},this.options=t||{},this.context=e||{}}return e.prototype.getOptions=function(){return this.options},e.prototype.setOptions=function(t){(0,s.equal)(this.options,t)||(this.previousOptions=this.options),this.options=t},e.prototype.unmount=function(){this.isMounted=!1},e.prototype.refreshClient=function(){var t=this.options&&this.options.client||this.context&&this.context.client;(0,o.invariant)(!!t,2);var e=!1;return t!==this.client&&(e=!0,this.client=t,this.cleanup()),{client:this.client,isNew:e}},e.prototype.verifyDocumentType=function(e,r){var i=(0,t.parser)(e);(0,t.operationName)(r),(0,t.operationName)(i.type);(0,o.invariant)(i.type===r,3)},e}(),u=function(r){function o(t){var e=t.options,i=t.context,s=t.forceUpdate,o=r.call(this,e,i)||this;return o.previousData={},o.currentObservable={},o.runLazy=!1,o.runLazyQuery=function(t){o.cleanup(),o.runLazy=!0,o.lazyOptions=t,o.forceUpdate()},o.getExecuteResult=function(){var t=o.getQueryResult();return o.startQuerySubscription(),t},o.obsRefetch=function(t){return o.currentObservable.query.refetch(t)},o.obsFetchMore=function(t){return o.currentObservable.query.fetchMore(t)},o.obsUpdateQuery=function(t){return o.currentObservable.query.updateQuery(t)},o.obsStartPolling=function(t){return o.currentObservable.query.startPolling(t)},o.obsStopPolling=function(){return o.currentObservable.query.stopPolling()},o.obsSubscribeToMore=function(t){return o.currentObservable.query.subscribeToMore(t)},o.forceUpdate=s,o}return(0,e.__extends)(o,r),o.prototype.execute=function(){this.refreshClient();var t=this.getOptions(),e=t.skip,r=t.query,i=t.ssr;(e||r!==this.previousData.query)&&(this.removeQuerySubscription(),this.previousData.query=r),this.updateObservableQuery(),this.isMounted&&this.startQuerySubscription();var s=!1===i;return this.getExecuteSsrResult(s)||this.getExecuteResult()},o.prototype.executeLazy=function(){return this.runLazy?[this.runLazyQuery,this.execute()]:[this.runLazyQuery,{loading:!1,networkStatus:i.NetworkStatus.ready,called:!1,data:void 0}]},o.prototype.fetchData=function(){var t=this.getOptions();if(t.skip||!1===t.ssr)return!1;var e=this.currentObservable.query;return!!e.getCurrentResult().loading&&e.result()},o.prototype.afterExecute=function(t){var e=this,r=(void 0===t?{}:t).lazy,i=void 0!==r&&r;return this.isMounted=!0,i&&!this.runLazy||(this.handleErrorOrCompleted(),setTimeout(function(){e.currentObservable.query&&e.currentObservable.query.resetQueryStoreErrors()})),this.unmount.bind(this)},o.prototype.cleanup=function(){this.removeQuerySubscription(),delete this.currentObservable.query,delete this.previousData.result},o.prototype.getOptions=function(){var t=r.prototype.getOptions.call(this),i=this.lazyOptions||{},s=(0,e.__assign)({},t,{variables:(0,e.__assign)({},t.variables,i.variables),context:(0,e.__assign)({},t.context,i.context)});return this.runLazy&&delete s.skip,s},o.prototype.getExecuteSsrResult=function(t){var e;if(this.context&&this.context.renderPromises){var r={loading:!0,networkStatus:i.NetworkStatus.loading,called:!0,data:void 0};if(t)return r;(e=this.context.renderPromises.addQueryPromise(this,this.getExecuteResult))||(e=r)}return e},o.prototype.prepareObservableQueryOptions=function(){var r=this.getOptions();this.verifyDocumentType(r.query,t.DocumentType.Query);var i=r.displayName||"Query";return this.context&&this.context.renderPromises&&("network-only"===r.fetchPolicy||"cache-and-network"===r.fetchPolicy)&&(r.fetchPolicy="cache-first"),(0,e.__assign)({},r,{displayName:i,context:r.context||{},metadata:{reactComponent:{displayName:i}}})},o.prototype.initializeObservableQuery=function(){if(this.context&&this.context.renderPromises&&(this.currentObservable.query=this.context.renderPromises.getSSRObservable(this.getOptions())),!this.currentObservable.query){var t=this.prepareObservableQueryOptions();this.previousData.observableQueryOptions=(0,e.__assign)({},t,{children:null}),this.currentObservable.query=this.refreshClient().client.watchQuery(t),this.context&&this.context.renderPromises&&this.context.renderPromises.registerSSRObservable(this.currentObservable.query,t)}},o.prototype.updateObservableQuery=function(){if(this.currentObservable.query){var t=(0,e.__assign)({},this.prepareObservableQueryOptions(),{children:null});(0,s.equal)(t,this.previousData.observableQueryOptions)||(this.previousData.observableQueryOptions=t,this.currentObservable.query.setOptions(t).catch(function(){}))}else this.initializeObservableQuery()},o.prototype.startQuerySubscription=function(){var t=this;if(!this.currentObservable.subscription&&!this.getOptions().skip){var e=this.currentObservable.query;this.currentObservable.subscription=e.subscribe({next:function(e){var r=e.loading,o=e.networkStatus,n=e.data,u=t.previousData.result;if(u){if(u.loading&&u.networkStatus===i.NetworkStatus.fetchMore&&(0,s.equal)(u.data,n))return;if(u.loading===r&&u.networkStatus===o&&(0,s.equal)(u.data,n))return}t.forceUpdate()},error:function(e){if(t.resubscribeToQuery(),!e.hasOwnProperty("graphQLErrors"))throw e;(0,s.equal)(e,t.previousData.error)||(t.previousData.error=e,t.forceUpdate())}})}},o.prototype.resubscribeToQuery=function(){this.removeQuerySubscription();var t=this.currentObservable.query.getLastError(),e=this.currentObservable.query.getLastResult();this.currentObservable.query.resetLastResults(),this.startQuerySubscription(),Object.assign(this.currentObservable.query,{lastError:t,lastResult:e})},o.prototype.getQueryResult=function(){var t=this.observableQueryFields(),r=this.getOptions();if(r.skip)t=(0,e.__assign)({},t,{data:void 0,error:void 0,loading:!1,called:!0});else{var s=this.currentObservable.query.getCurrentResult(),o=s.loading,n=s.partial,u=s.networkStatus,a=s.errors,c=s.error,p=s.data;if(a&&a.length>0&&(c=new i.ApolloError({graphQLErrors:a})),t=(0,e.__assign)({},t,{loading:o,networkStatus:u,error:c,called:!0}),o){var l=this.previousData.result&&this.previousData.result.data;t.data=l&&p?(0,e.__assign)({},l,p):l||p}else if(c)Object.assign(t,{data:(this.currentObservable.query.getLastResult()||{}).data});else{var h=this.currentObservable.query.options.fetchPolicy;if(r.partialRefetch&&!p&&n&&"cache-only"!==h)return Object.assign(t,{loading:!0,networkStatus:i.NetworkStatus.loading}),t.refetch(),t;t.data=p}}return t.client=this.client,this.previousData.loading=this.previousData.result&&this.previousData.result.loading||!1,this.previousData.result=t,t},o.prototype.handleErrorOrCompleted=function(){var t=this.currentObservable.query.getCurrentResult(),e=t.data,r=t.loading,i=t.error;if(!r){var o=this.getOptions(),n=o.query,u=o.variables,a=o.onCompleted,c=o.onError;if(this.previousOptions&&!this.previousData.loading&&(0,s.equal)(this.previousOptions.query,n)&&(0,s.equal)(this.previousOptions.variables,u))return;a&&!i?a(e):c&&i&&c(i)}},o.prototype.removeQuerySubscription=function(){this.currentObservable.subscription&&(this.currentObservable.subscription.unsubscribe(),delete this.currentObservable.subscription)},o.prototype.observableQueryFields=function(){return{variables:this.currentObservable.query.variables,refetch:this.obsRefetch,fetchMore:this.obsFetchMore,updateQuery:this.obsUpdateQuery,startPolling:this.obsStartPolling,stopPolling:this.obsStopPolling,subscribeToMore:this.obsSubscribeToMore}},o}(n);function a(i,o,n){void 0===n&&(n=!1);var a=(0,r.useContext)((0,t.getApolloContext)()),c=(0,r.useReducer)(function(t){return t+1},0),p=c[0],l=c[1],h=o?(0,e.__assign)({},o,{query:i}):{query:i},b=(0,r.useRef)();b.current||(b.current=new u({options:h,context:a,forceUpdate:l}));var v=b.current;v.setOptions(h),v.context=a;var y,f,d,g={options:(0,e.__assign)({},h,{onError:void 0,onCompleted:void 0}),context:a,tick:p},O=(y=function(){return n?v.executeLazy():v.execute()},f=g,(d=(0,r.useRef)()).current&&(0,s.equal)(f,d.current.key)||(d.current={key:f,value:y()}),d.current.value),x=n?O[1]:O;return(0,r.useEffect)(function(){return v.afterExecute({lazy:n})},[x.loading,x.networkStatus,x.error,x.data]),(0,r.useEffect)(function(){return function(){return v.cleanup()}},[]),O}var c=function(r){function o(e){var i=e.options,s=e.context,o=e.result,n=e.setResult,u=r.call(this,i,s)||this;return u.runMutation=function(t){void 0===t&&(t={}),u.onMutationStart();var e=u.generateNewMutationId();return u.mutate(t).then(function(t){return u.onMutationCompleted(t,e),t}).catch(function(t){if(u.onMutationError(t,e),!u.getOptions().onError)throw t})},u.verifyDocumentType(i.mutation,t.DocumentType.Mutation),u.result=o,u.setResult=n,u.mostRecentMutationId=0,u}return(0,e.__extends)(o,r),o.prototype.execute=function(e){return this.isMounted=!0,this.verifyDocumentType(this.getOptions().mutation,t.DocumentType.Mutation),e.client=this.refreshClient().client,[this.runMutation,e]},o.prototype.afterExecute=function(){return this.isMounted=!0,this.unmount.bind(this)},o.prototype.cleanup=function(){},o.prototype.mutate=function(t){var r=this.getOptions(),i=r.mutation,s=r.variables,o=r.optimisticResponse,n=r.update,u=r.context,a=void 0===u?{}:u,c=r.awaitRefetchQueries,p=void 0!==c&&c,l=r.fetchPolicy,h=(0,e.__assign)({},t),b=Object.assign({},s,h.variables);return delete h.variables,this.refreshClient().client.mutate((0,e.__assign)({mutation:i,optimisticResponse:o,refetchQueries:h.refetchQueries||this.getOptions().refetchQueries,awaitRefetchQueries:p,update:n,context:a,fetchPolicy:l,variables:b},h))},o.prototype.onMutationStart=function(){this.result.loading||this.getOptions().ignoreResults||this.updateResult({loading:!0,error:void 0,data:void 0,called:!0})},o.prototype.onMutationCompleted=function(t,e){var r=this.getOptions(),s=r.onCompleted,o=r.ignoreResults,n=t.data,u=t.errors,a=u&&u.length>0?new i.ApolloError({graphQLErrors:u}):void 0;this.isMostRecentMutation(e)&&!o&&this.updateResult({called:!0,loading:!1,data:n,error:a}),s&&s(n)},o.prototype.onMutationError=function(t,e){var r=this.getOptions().onError;this.isMostRecentMutation(e)&&this.updateResult({loading:!1,error:t,data:void 0,called:!0}),r&&r(t)},o.prototype.generateNewMutationId=function(){return++this.mostRecentMutationId},o.prototype.isMostRecentMutation=function(t){return this.mostRecentMutationId===t},o.prototype.updateResult=function(t){!this.isMounted||this.previousResult&&(0,s.equal)(this.previousResult,t)||(this.setResult(t),this.previousResult=t)},o}(n);var p=function(t){function r(e){var r=e.options,i=e.context,s=e.setResult,o=t.call(this,r,i)||this;return o.currentObservable={},o.setResult=s,o.initialize(r),o}return(0,e.__extends)(r,t),r.prototype.execute=function(t){if(!0===this.getOptions().skip)return this.cleanup(),{loading:!1,error:void 0,data:void 0,variables:this.getOptions().variables};var r=t;this.refreshClient().isNew&&(r=this.getLoadingResult());var i=this.getOptions().shouldResubscribe;return"function"==typeof i&&(i=!!i(this.getOptions())),!1!==i&&this.previousOptions&&Object.keys(this.previousOptions).length>0&&(this.previousOptions.subscription!==this.getOptions().subscription||!(0,s.equal)(this.previousOptions.variables,this.getOptions().variables)||this.previousOptions.skip!==this.getOptions().skip)&&(this.cleanup(),r=this.getLoadingResult()),this.initialize(this.getOptions()),this.startSubscription(),this.previousOptions=this.getOptions(),(0,e.__assign)({},r,{variables:this.getOptions().variables})},r.prototype.afterExecute=function(){this.isMounted=!0},r.prototype.cleanup=function(){this.endSubscription(),delete this.currentObservable.query},r.prototype.initialize=function(t){this.currentObservable.query||!0===this.getOptions().skip||(this.currentObservable.query=this.refreshClient().client.subscribe({query:t.subscription,variables:t.variables,fetchPolicy:t.fetchPolicy}))},r.prototype.startSubscription=function(){this.currentObservable.subscription||(this.currentObservable.subscription=this.currentObservable.query.subscribe({next:this.updateCurrentData.bind(this),error:this.updateError.bind(this),complete:this.completeSubscription.bind(this)}))},r.prototype.getLoadingResult=function(){return{loading:!0,error:void 0,data:void 0}},r.prototype.updateResult=function(t){this.isMounted&&this.setResult(t)},r.prototype.updateCurrentData=function(t){var e=this.getOptions().onSubscriptionData;this.updateResult({data:t.data,loading:!1,error:void 0}),e&&e({client:this.refreshClient().client,subscriptionData:t})},r.prototype.updateError=function(t){this.updateResult({error:t,loading:!1})},r.prototype.completeSubscription=function(){var t=this.getOptions().onSubscriptionComplete;t&&t(),this.endSubscription()},r.prototype.endSubscription=function(){this.currentObservable.subscription&&(this.currentObservable.subscription.unsubscribe(),delete this.currentObservable.subscription)},r}(n);var l=function(){function t(){this.queryPromises=new Map,this.queryInfoTrie=new Map}return t.prototype.registerSSRObservable=function(t,e){this.lookupQueryInfo(e).observable=t},t.prototype.getSSRObservable=function(t){return this.lookupQueryInfo(t).observable},t.prototype.addQueryPromise=function(t,e){return this.lookupQueryInfo(t.getOptions()).seen?e():(this.queryPromises.set(t.getOptions(),new Promise(function(e){e(t.fetchData())})),null)},t.prototype.hasPromises=function(){return this.queryPromises.size>0},t.prototype.consumeAndAwaitPromises=function(){var t=this,e=[];return this.queryPromises.forEach(function(r,i){t.lookupQueryInfo(i).seen=!0,e.push(r)}),this.queryPromises.clear(),Promise.all(e)},t.prototype.lookupQueryInfo=function(t){var e=this.queryInfoTrie,r=t.query,i=t.variables,s=e.get(r)||new Map;e.has(r)||e.set(r,s);var o=JSON.stringify(i),n=s.get(o)||{seen:!1,observable:null};return s.has(o)||s.set(o,n),n},t}();exports.RenderPromises=l;
exports.__esModule=!0,exports.useApolloClient=function(){var e=r.default.useContext((0,t.getApolloContext)()).client;return(0,o.invariant)(e,1),e},exports.useLazyQuery=function(t,e){return c(t,e,!0)},exports.useMutation=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useState)({called:!1,loading:!1}),u=n[0],a=n[1],c=s?(0,e.__assign)({},s,{mutation:i}):{mutation:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new p({options:c,context:o,result:u,setResult:a}));return l.current}();return h.setOptions(c),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),h.execute(u)},exports.useQuery=function(t,e){return c(t,e,!1)},exports.useSubscription=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=s?(0,e.__assign)({},s,{subscription:i}):{subscription:i},u=(0,r.useState)({loading:!n.skip,error:void 0,data:void 0}),a=u[0],c=u[1],p=(0,r.useRef)();var h=function(){p.current||(p.current=new l({options:n,context:o,setResult:c}));return p.current}();return h.setOptions(n),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),(0,r.useEffect)(function(){return h.cleanup.bind(h)},[]),h.execute(a)},exports.RenderPromises=exports.resetApolloContext=exports.ApolloProvider=exports.ApolloConsumer=void 0;var t=require("@apollo/react-common");exports.getApolloContext=t.getApolloContext,exports.ApolloConsumer=t.ApolloConsumer,exports.ApolloProvider=t.ApolloProvider,exports.resetApolloContext=t.resetApolloContext;var e=require("tslib"),r=function(t){if(t&&t.__esModule)return t;var e=n();if(e&&e.has(t))return e.get(t);var r={};if(null!=t){var i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in t)if(Object.prototype.hasOwnProperty.call(t,s)){var o=i?Object.getOwnPropertyDescriptor(t,s):null;o&&(o.get||o.set)?Object.defineProperty(r,s,o):r[s]=t[s]}}r.default=t,e&&e.set(t,r);return r}(require("react")),i=require("apollo-client"),s=require("@wry/equality"),o=require("ts-invariant");function n(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return n=function(){return t},t}var u=function(){function e(t,e){this.isMounted=!1,this.previousOptions={},this.context={},this.options={},this.options=t||{},this.context=e||{}}return e.prototype.getOptions=function(){return this.options},e.prototype.setOptions=function(t){(0,s.equal)(this.options,t)||(this.previousOptions=this.options),this.options=t},e.prototype.unmount=function(){this.isMounted=!1},e.prototype.refreshClient=function(){var t=this.options&&this.options.client||this.context&&this.context.client;(0,o.invariant)(!!t,2);var e=!1;return t!==this.client&&(e=!0,this.client=t,this.cleanup()),{client:this.client,isNew:e}},e.prototype.verifyDocumentType=function(e,r){var i=(0,t.parser)(e);(0,t.operationName)(r),(0,t.operationName)(i.type);(0,o.invariant)(i.type===r,3)},e}(),a=function(r){function o(t){var e=t.options,i=t.context,s=t.forceUpdate,o=r.call(this,e,i)||this;return o.previousData={},o.currentObservable={},o.runLazy=!1,o.runLazyQuery=function(t){o.cleanup(),o.runLazy=!0,o.lazyOptions=t,o.forceUpdate()},o.getExecuteResult=function(){var t=o.getQueryResult();return o.startQuerySubscription(),t},o.obsRefetch=function(t){return o.currentObservable.query.refetch(t)},o.obsFetchMore=function(t){return o.currentObservable.query.fetchMore(t)},o.obsUpdateQuery=function(t){return o.currentObservable.query.updateQuery(t)},o.obsStartPolling=function(t){o.currentObservable&&o.currentObservable.query&&o.currentObservable.query.startPolling(t)},o.obsStopPolling=function(){o.currentObservable&&o.currentObservable.query&&o.currentObservable.query.stopPolling()},o.obsSubscribeToMore=function(t){return o.currentObservable.query.subscribeToMore(t)},o.forceUpdate=s,o}return(0,e.__extends)(o,r),o.prototype.execute=function(){this.refreshClient();var t=this.getOptions(),e=t.skip,r=t.query,i=t.ssr;(e||r!==this.previousData.query)&&(this.removeQuerySubscription(),this.previousData.query=r),this.updateObservableQuery(),this.isMounted&&this.startQuerySubscription();var s=!1===i;return this.getExecuteSsrResult(s)||this.getExecuteResult()},o.prototype.executeLazy=function(){return this.runLazy?[this.runLazyQuery,this.execute()]:[this.runLazyQuery,{loading:!1,networkStatus:i.NetworkStatus.ready,called:!1,data:void 0}]},o.prototype.fetchData=function(){var t=this.getOptions();if(t.skip||!1===t.ssr)return!1;var e=this.currentObservable.query;return!!e.getCurrentResult().loading&&e.result()},o.prototype.afterExecute=function(t){var e=this,r=(void 0===t?{}:t).lazy,i=void 0!==r&&r;return this.isMounted=!0,i&&!this.runLazy||(this.handleErrorOrCompleted(),setTimeout(function(){e.currentObservable.query&&e.currentObservable.query.resetQueryStoreErrors()})),this.unmount.bind(this)},o.prototype.cleanup=function(){this.removeQuerySubscription(),delete this.currentObservable.query,delete this.previousData.result},o.prototype.getOptions=function(){var t=r.prototype.getOptions.call(this),i=this.lazyOptions||{},s=(0,e.__assign)({},t,{variables:(0,e.__assign)({},t.variables,i.variables),context:(0,e.__assign)({},t.context,i.context)});return this.runLazy&&delete s.skip,s},o.prototype.getExecuteSsrResult=function(t){var e;if(this.context&&this.context.renderPromises){var r={loading:!0,networkStatus:i.NetworkStatus.loading,called:!0,data:void 0};if(t)return r;(e=this.context.renderPromises.addQueryPromise(this,this.getExecuteResult))||(e=r)}return e},o.prototype.prepareObservableQueryOptions=function(){var r=this.getOptions();this.verifyDocumentType(r.query,t.DocumentType.Query);var i=r.displayName||"Query";return this.context&&this.context.renderPromises&&("network-only"===r.fetchPolicy||"cache-and-network"===r.fetchPolicy)&&(r.fetchPolicy="cache-first"),(0,e.__assign)({},r,{displayName:i,context:r.context||{},metadata:{reactComponent:{displayName:i}}})},o.prototype.initializeObservableQuery=function(){if(this.context&&this.context.renderPromises&&(this.currentObservable.query=this.context.renderPromises.getSSRObservable(this.getOptions())),!this.currentObservable.query){var t=this.prepareObservableQueryOptions();this.previousData.observableQueryOptions=(0,e.__assign)({},t,{children:null}),this.currentObservable.query=this.refreshClient().client.watchQuery(t),this.context&&this.context.renderPromises&&this.context.renderPromises.registerSSRObservable(this.currentObservable.query,t)}},o.prototype.updateObservableQuery=function(){if(this.currentObservable.query){var t=(0,e.__assign)({},this.prepareObservableQueryOptions(),{children:null});(0,s.equal)(t,this.previousData.observableQueryOptions)||(this.previousData.observableQueryOptions=t,this.currentObservable.query.setOptions(t).catch(function(){}))}else this.initializeObservableQuery()},o.prototype.startQuerySubscription=function(){var t=this;if(!this.currentObservable.subscription&&!this.getOptions().skip){var e=this.currentObservable.query;this.currentObservable.subscription=e.subscribe({next:function(e){var r=e.loading,o=e.networkStatus,n=e.data,u=t.previousData.result;if(u){if(u.loading&&u.networkStatus===i.NetworkStatus.fetchMore&&(0,s.equal)(u.data,n))return;if(u.loading===r&&u.networkStatus===o&&(0,s.equal)(u.data,n))return}t.forceUpdate()},error:function(e){if(t.resubscribeToQuery(),!e.hasOwnProperty("graphQLErrors"))throw e;var r=t.previousData.result;(r&&r.loading||!(0,s.equal)(e,t.previousData.error))&&(t.previousData.error=e,t.forceUpdate())}})}},o.prototype.resubscribeToQuery=function(){this.removeQuerySubscription();var t=this.currentObservable.query.getLastError(),e=this.currentObservable.query.getLastResult();this.currentObservable.query.resetLastResults(),this.startQuerySubscription(),Object.assign(this.currentObservable.query,{lastError:t,lastResult:e})},o.prototype.getQueryResult=function(){var t=this.observableQueryFields(),r=this.getOptions();if(r.skip)t=(0,e.__assign)({},t,{data:void 0,error:void 0,loading:!1,called:!0});else{var s=this.currentObservable.query.getCurrentResult(),o=s.loading,n=s.partial,u=s.networkStatus,a=s.errors,c=s.error,p=s.data;if(a&&a.length>0&&(c=new i.ApolloError({graphQLErrors:a})),t=(0,e.__assign)({},t,{loading:o,networkStatus:u,error:c,called:!0}),o){var l=this.previousData.result&&this.previousData.result.data;t.data=l&&p?(0,e.__assign)({},l,p):l||p}else if(c)Object.assign(t,{data:(this.currentObservable.query.getLastResult()||{}).data});else{var h=this.currentObservable.query.options.fetchPolicy;if(r.partialRefetch&&!p&&n&&"cache-only"!==h)return Object.assign(t,{loading:!0,networkStatus:i.NetworkStatus.loading}),t.refetch(),t;t.data=p}}return t.client=this.client,this.previousData.loading=this.previousData.result&&this.previousData.result.loading||!1,this.previousData.result=t,t},o.prototype.handleErrorOrCompleted=function(){var t=this.currentObservable.query;if(t){var e=t.getCurrentResult(),r=e.data,i=e.loading,o=e.error;if(!i){var n=this.getOptions(),u=n.query,a=n.variables,c=n.onCompleted,p=n.onError;if(this.previousOptions&&!this.previousData.loading&&(0,s.equal)(this.previousOptions.query,u)&&(0,s.equal)(this.previousOptions.variables,a))return;c&&!o?c(r):p&&o&&p(o)}}},o.prototype.removeQuerySubscription=function(){this.currentObservable.subscription&&(this.currentObservable.subscription.unsubscribe(),delete this.currentObservable.subscription)},o.prototype.observableQueryFields=function(){return{variables:this.currentObservable.query.variables,refetch:this.obsRefetch,fetchMore:this.obsFetchMore,updateQuery:this.obsUpdateQuery,startPolling:this.obsStartPolling,stopPolling:this.obsStopPolling,subscribeToMore:this.obsSubscribeToMore}},o}(u);function c(i,o,n){void 0===n&&(n=!1);var u=(0,r.useContext)((0,t.getApolloContext)()),c=(0,r.useReducer)(function(t){return t+1},0),p=c[0],l=c[1],h=o?(0,e.__assign)({},o,{query:i}):{query:i},b=(0,r.useRef)();b.current||(b.current=new a({options:h,context:u,forceUpdate:l}));var v=b.current;v.setOptions(h),v.context=u;var f,y,d,g={options:(0,e.__assign)({},h,{onError:void 0,onCompleted:void 0}),context:u,tick:p},O=(f=function(){return n?v.executeLazy():v.execute()},y=g,(d=(0,r.useRef)()).current&&(0,s.equal)(y,d.current.key)||(d.current={key:y,value:f()}),d.current.value),x=n?O[1]:O;return(0,r.useEffect)(function(){return v.afterExecute({lazy:n})},n?void 0:[x.loading,x.networkStatus,x.error,x.data]),(0,r.useEffect)(function(){return function(){return v.cleanup()}},[]),O}var p=function(r){function o(e){var i=e.options,s=e.context,o=e.result,n=e.setResult,u=r.call(this,i,s)||this;return u.runMutation=function(t){void 0===t&&(t={}),u.onMutationStart();var e=u.generateNewMutationId();return u.mutate(t).then(function(t){return u.onMutationCompleted(t,e),t}).catch(function(t){if(u.onMutationError(t,e),!u.getOptions().onError)throw t})},u.verifyDocumentType(i.mutation,t.DocumentType.Mutation),u.result=o,u.setResult=n,u.mostRecentMutationId=0,u}return(0,e.__extends)(o,r),o.prototype.execute=function(e){return this.isMounted=!0,this.verifyDocumentType(this.getOptions().mutation,t.DocumentType.Mutation),e.client=this.refreshClient().client,[this.runMutation,e]},o.prototype.afterExecute=function(){return this.isMounted=!0,this.unmount.bind(this)},o.prototype.cleanup=function(){},o.prototype.mutate=function(t){var r=this.getOptions(),i=r.mutation,s=r.variables,o=r.optimisticResponse,n=r.update,u=r.context,a=void 0===u?{}:u,c=r.awaitRefetchQueries,p=void 0!==c&&c,l=r.fetchPolicy,h=(0,e.__assign)({},t),b=Object.assign({},s,h.variables);return delete h.variables,this.refreshClient().client.mutate((0,e.__assign)({mutation:i,optimisticResponse:o,refetchQueries:h.refetchQueries||this.getOptions().refetchQueries,awaitRefetchQueries:p,update:n,context:a,fetchPolicy:l,variables:b},h))},o.prototype.onMutationStart=function(){this.result.loading||this.getOptions().ignoreResults||this.updateResult({loading:!0,error:void 0,data:void 0,called:!0})},o.prototype.onMutationCompleted=function(t,e){var r=this.getOptions(),s=r.onCompleted,o=r.ignoreResults,n=t.data,u=t.errors,a=u&&u.length>0?new i.ApolloError({graphQLErrors:u}):void 0;this.isMostRecentMutation(e)&&!o&&this.updateResult({called:!0,loading:!1,data:n,error:a}),s&&s(n)},o.prototype.onMutationError=function(t,e){var r=this.getOptions().onError;this.isMostRecentMutation(e)&&this.updateResult({loading:!1,error:t,data:void 0,called:!0}),r&&r(t)},o.prototype.generateNewMutationId=function(){return++this.mostRecentMutationId},o.prototype.isMostRecentMutation=function(t){return this.mostRecentMutationId===t},o.prototype.updateResult=function(t){!this.isMounted||this.previousResult&&(0,s.equal)(this.previousResult,t)||(this.setResult(t),this.previousResult=t)},o}(u);var l=function(t){function r(e){var r=e.options,i=e.context,s=e.setResult,o=t.call(this,r,i)||this;return o.currentObservable={},o.setResult=s,o.initialize(r),o}return(0,e.__extends)(r,t),r.prototype.execute=function(t){if(!0===this.getOptions().skip)return this.cleanup(),{loading:!1,error:void 0,data:void 0,variables:this.getOptions().variables};var r=t;this.refreshClient().isNew&&(r=this.getLoadingResult());var i=this.getOptions().shouldResubscribe;return"function"==typeof i&&(i=!!i(this.getOptions())),!1!==i&&this.previousOptions&&Object.keys(this.previousOptions).length>0&&(this.previousOptions.subscription!==this.getOptions().subscription||!(0,s.equal)(this.previousOptions.variables,this.getOptions().variables)||this.previousOptions.skip!==this.getOptions().skip)&&(this.cleanup(),r=this.getLoadingResult()),this.initialize(this.getOptions()),this.startSubscription(),this.previousOptions=this.getOptions(),(0,e.__assign)({},r,{variables:this.getOptions().variables})},r.prototype.afterExecute=function(){this.isMounted=!0},r.prototype.cleanup=function(){this.endSubscription(),delete this.currentObservable.query},r.prototype.initialize=function(t){this.currentObservable.query||!0===this.getOptions().skip||(this.currentObservable.query=this.refreshClient().client.subscribe({query:t.subscription,variables:t.variables,fetchPolicy:t.fetchPolicy}))},r.prototype.startSubscription=function(){this.currentObservable.subscription||(this.currentObservable.subscription=this.currentObservable.query.subscribe({next:this.updateCurrentData.bind(this),error:this.updateError.bind(this),complete:this.completeSubscription.bind(this)}))},r.prototype.getLoadingResult=function(){return{loading:!0,error:void 0,data:void 0}},r.prototype.updateResult=function(t){this.isMounted&&this.setResult(t)},r.prototype.updateCurrentData=function(t){var e=this.getOptions().onSubscriptionData;this.updateResult({data:t.data,loading:!1,error:void 0}),e&&e({client:this.refreshClient().client,subscriptionData:t})},r.prototype.updateError=function(t){this.updateResult({error:t,loading:!1})},r.prototype.completeSubscription=function(){var t=this.getOptions().onSubscriptionComplete;t&&t(),this.endSubscription()},r.prototype.endSubscription=function(){this.currentObservable.subscription&&(this.currentObservable.subscription.unsubscribe(),delete this.currentObservable.subscription)},r}(u);var h=function(){function t(){this.queryPromises=new Map,this.queryInfoTrie=new Map}return t.prototype.registerSSRObservable=function(t,e){this.lookupQueryInfo(e).observable=t},t.prototype.getSSRObservable=function(t){return this.lookupQueryInfo(t).observable},t.prototype.addQueryPromise=function(t,e){return this.lookupQueryInfo(t.getOptions()).seen?e():(this.queryPromises.set(t.getOptions(),new Promise(function(e){e(t.fetchData())})),null)},t.prototype.hasPromises=function(){return this.queryPromises.size>0},t.prototype.consumeAndAwaitPromises=function(){var t=this,e=[];return this.queryPromises.forEach(function(r,i){t.lookupQueryInfo(i).seen=!0,e.push(r)}),this.queryPromises.clear(),Promise.all(e)},t.prototype.lookupQueryInfo=function(t){var e=this.queryInfoTrie,r=t.query,i=t.variables,s=e.get(r)||new Map;e.has(r)||e.set(r,s);var o=JSON.stringify(i),n=s.get(o)||{seen:!1,observable:null};return s.has(o)||s.set(o,n),n},t}();exports.RenderPromises=h;

@@ -82,5 +82,11 @@ import { parser, operationName, DocumentType, getApolloContext } from '@apollo/react-common';

_this.obsStartPolling = function (pollInterval) {
return _this.currentObservable.query.startPolling(pollInterval);
_this.currentObservable &&
_this.currentObservable.query &&
_this.currentObservable.query.startPolling(pollInterval);
};
_this.obsStopPolling = function () { return _this.currentObservable.query.stopPolling(); };
_this.obsStopPolling = function () {
_this.currentObservable &&
_this.currentObservable.query &&
_this.currentObservable.query.stopPolling();
};
_this.obsSubscribeToMore = function (options) { return _this.currentObservable.query.subscribeToMore(options); };

@@ -235,3 +241,5 @@ _this.forceUpdate = forceUpdate;

throw error;
if (!equal(error, _this.previousData.error)) {
var previousResult = _this.previousData.result;
if ((previousResult && previousResult.loading) ||
!equal(error, _this.previousData.error)) {
_this.previousData.error = error;

@@ -306,3 +314,6 @@ _this.forceUpdate();

QueryData.prototype.handleErrorOrCompleted = function () {
var _a = this.currentObservable.query.getCurrentResult(), data = _a.data, loading = _a.loading, error = _a.error;
var obsQuery = this.currentObservable.query;
if (!obsQuery)
return;
var _a = obsQuery.getCurrentResult(), data = _a.data, loading = _a.loading, error = _a.error;
if (!loading) {

@@ -378,8 +389,10 @@ var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError;

: result;
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
queryResult.loading,
queryResult.networkStatus,
queryResult.error,
queryResult.data
]);
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, lazy
? undefined
: [
queryResult.loading,
queryResult.networkStatus,
queryResult.error,
queryResult.data
]);
useEffect(function () {

@@ -386,0 +399,0 @@ return function () { return queryData.cleanup(); };

@@ -28,4 +28,6 @@ (function (global, factory) {

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var OperationData = function () {

@@ -128,7 +130,7 @@ function OperationData(options, context) {

_this.obsStartPolling = function (pollInterval) {
return _this.currentObservable.query.startPolling(pollInterval);
_this.currentObservable && _this.currentObservable.query && _this.currentObservable.query.startPolling(pollInterval);
};
_this.obsStopPolling = function () {
return _this.currentObservable.query.stopPolling();
_this.currentObservable && _this.currentObservable.query && _this.currentObservable.query.stopPolling();
};

@@ -326,4 +328,5 @@

if (!error.hasOwnProperty('graphQLErrors')) throw error;
var previousResult = _this.previousData.result;
if (!(0, _equality.equal)(error, _this.previousData.error)) {
if (previousResult && previousResult.loading || !(0, _equality.equal)(error, _this.previousData.error)) {
_this.previousData.error = error;

@@ -413,3 +416,6 @@

QueryData.prototype.handleErrorOrCompleted = function () {
var _a = this.currentObservable.query.getCurrentResult(),
var obsQuery = this.currentObservable.query;
if (!obsQuery) return;
var _a = obsQuery.getCurrentResult(),
data = _a.data,

@@ -521,3 +527,3 @@ loading = _a.loading,

});
}, [queryResult.loading, queryResult.networkStatus, queryResult.error, queryResult.data]);
}, lazy ? undefined : [queryResult.loading, queryResult.networkStatus, queryResult.error, queryResult.data]);
(0, _react.useEffect)(function () {

@@ -524,0 +530,0 @@ return function () {

@@ -31,8 +31,10 @@ import * as tslib_1 from "tslib";

: result;
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
queryResult.loading,
queryResult.networkStatus,
queryResult.error,
queryResult.data
]);
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, lazy
? undefined
: [
queryResult.loading,
queryResult.networkStatus,
queryResult.error,
queryResult.data
]);
useEffect(function () {

@@ -39,0 +41,0 @@ return function () { return queryData.cleanup(); };

{
"name": "@apollo/react-hooks",
"description": "React Apollo Hooks.",
"version": "3.1.0",
"version": "3.1.1",
"author": "opensource@apollographql.com",

@@ -46,3 +46,3 @@ "keywords": [

"dependencies": {
"@apollo/react-common": "^3.1.0",
"@apollo/react-common": "^3.1.1",
"@wry/equality": "^0.1.9",

@@ -61,6 +61,6 @@ "ts-invariant": "^0.4.4",

"rollup": "1.20.3",
"tsc-watch": "2.4.0",
"tsc-watch": "3.0.1",
"typescript": "3.5.3"
},
"gitHead": "3bc12b7f5b2064acc7ec0e15ec59cd2acfa61d49"
"gitHead": "1ad1e76c298b8c8ff9a49c03a8dec4b1da812625"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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