@apollo/react-hooks
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -15,3 +15,3 @@ import { ApolloContextValue, OperationVariables, ExecutionResult, MutationFunctionOptions, MutationResult } from '@apollo/react-common'; | ||
}); | ||
execute(result: MutationResult<TData>): [(options?: MutationFunctionOptions<TData, TVariables> | undefined) => Promise<void | ExecutionResult<TData>>, MutationResult<TData>]; | ||
execute(result: MutationResult<TData>): [(options?: MutationFunctionOptions<TData, TVariables> | undefined) => Promise<ExecutionResult<TData>>, MutationResult<TData>]; | ||
afterExecute(): () => void; | ||
@@ -18,0 +18,0 @@ cleanup(): void; |
@@ -170,3 +170,6 @@ import * as tslib_1 from "tslib"; | ||
throw error; | ||
_this.forceUpdate(); | ||
if (!isEqual(error, _this.previousData.error)) { | ||
_this.previousData.error = error; | ||
_this.forceUpdate(); | ||
} | ||
} | ||
@@ -173,0 +176,0 @@ }); |
@@ -308,3 +308,7 @@ exports.__esModule = true; | ||
_this.forceUpdate(); | ||
if (!(0, _equality.equal)(error, _this.previousData.error)) { | ||
_this.previousData.error = error; | ||
_this.forceUpdate(); | ||
} | ||
} | ||
@@ -311,0 +315,0 @@ }); |
@@ -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],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 a(t,e,!1)},exports.useSubscription=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useState)({loading:!0,error:void 0,data:void 0}),u=n[0],a=n[1],p=s?(0,e.__assign)({},s,{subscription:i}):{subscription:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new c({options:p,context:o,setResult:a}));return l.current}();return h.setOptions(p),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),(0,r.useEffect)(function(){return h.cleanup.bind(h)},[]),h.execute(u)},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.runLazy=!0,o.lazyOptions=t,o.forceUpdate()},o.getExecuteResult=function(){var t=o.getQueryResult();return o.startQuerySubscription(),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;return(e||r!==this.previousData.query)&&(this.removeQuerySubscription(),this.previousData.query=r),this.updateObservableQuery(),this.isMounted&&this.startQuerySubscription(),this.getExecuteSsrResult()||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(){if(this.getOptions().skip)return!1;var t=this.getOptions(),r=(t.children,t.ssr),i=(t.displayName,t.skip,t.onCompleted,t.onError,t.partialRefetch,(0,e.__rest)(t,["children","ssr","displayName","skip","onCompleted","onError","partialRefetch"])),s=i.fetchPolicy;if(!1===r)return!1;"network-only"!==s&&"cache-and-network"!==s||(s="cache-first");var o=this.refreshClient().client.watchQuery((0,e.__assign)({},i,{fetchPolicy:s}));return this.context&&this.context.renderPromises&&this.context.renderPromises.registerSSRObservable(o,this.getOptions()),!!this.currentObservable.query.getCurrentResult().loading&&o.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(){var t,e={loading:!0,networkStatus:i.NetworkStatus.loading,called:!0,data:{}};return this.context&&this.context.renderPromises&&((t=this.context.renderPromises.addQueryPromise(this,this.getExecuteResult))||(t=e)),t},o.prototype.prepareObservableQueryOptions=function(){this.verifyDocumentType(this.getOptions().query,t.DocumentType.Query);var r=this.getOptions().displayName||"Query";return(0,e.__assign)({},this.getOptions(),{displayName:r,context:this.getOptions().context||{},metadata:{reactComponent:{displayName:r}}})},o.prototype.observableQueryFields=function(t){return{variables:t.variables,refetch:t.refetch.bind(t),fetchMore:t.fetchMore.bind(t),updateQuery:t.updateQuery.bind(t),startPolling:t.startPolling.bind(t),stopPolling:t.stopPolling.bind(t),subscribeToMore:t.subscribeToMore.bind(t)}},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)}},o.prototype.updateObservableQuery=function(){this.currentObservable.query||this.initializeObservableQuery();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(){}))},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,i=e.networkStatus,o=e.data;t.previousData.result&&t.previousData.result.loading===r&&t.previousData.result.networkStatus===i&&(0,s.equal)(t.previousData.result.data,o||{})||t.forceUpdate()},error:function(e){if(t.resubscribeToQuery(),!e.hasOwnProperty("graphQLErrors"))throw 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={data:Object.create(null)};if(Object.assign(t,this.observableQueryFields(this.currentObservable.query)),this.getOptions().skip)t=(0,e.__assign)({},t,{data:void 0,error:void 0,loading:!1,called:!0});else{var r=this.currentObservable.query.getCurrentResult(),s=r.loading,o=r.partial,n=r.networkStatus,u=r.errors,a=r.error,p=r.data;if(p=p||Object.create(null),u&&u.length>0&&(a=new i.ApolloError({graphQLErrors:u})),Object.assign(t,{loading:s,networkStatus:n,error:a,called:!0}),s){var c=this.previousData.result?this.previousData.result.data:{};Object.assign(t.data,c,p)}else if(a)Object.assign(t,{data:(this.currentObservable.query.getLastResult()||{}).data});else{var l=this.currentObservable.query.options.fetchPolicy;if(this.getOptions().partialRefetch&&0===Object.keys(p).length&&o&&"cache-only"!==l)return Object.assign(t,{loading:!0,networkStatus:i.NetworkStatus.loading}),t.refetch(),t;Object.assign(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,p=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):p&&i&&p(i)}},o.prototype.removeQuerySubscription=function(){this.currentObservable.subscription&&(this.currentObservable.subscription.unsubscribe(),delete this.currentObservable.subscription)},o}(n);function a(i,o,n){void 0===n&&(n=!1);var a=(0,r.useContext)((0,t.getApolloContext)()),p=(0,r.useReducer)(function(t){return t+1},0),c=p[0],l=p[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,d,f,g=(y=function(){return n?v.executeLazy():v.execute()},d={options:h,context:a,tick:c},(f=(0,r.useRef)()).current&&(0,s.equal)(d,f.current.key)||(f.current={key:d,value:y()}),f.current.value);return(0,r.useEffect)(function(){return v.afterExecute({lazy:n})},[g]),(0,r.useEffect)(function(){return function(){return v.cleanup()}},[]),g}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),[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,p=r.awaitRefetchQueries,c=void 0!==p&&p,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:c,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 c=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){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.endSubscription(),delete this.currentObservable.query,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||(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 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],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 a(t,e,!1)},exports.useSubscription=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useState)({loading:!0,error:void 0,data:void 0}),u=n[0],a=n[1],p=s?(0,e.__assign)({},s,{subscription:i}):{subscription:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new c({options:p,context:o,setResult:a}));return l.current}();return h.setOptions(p),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),(0,r.useEffect)(function(){return h.cleanup.bind(h)},[]),h.execute(u)},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.runLazy=!0,o.lazyOptions=t,o.forceUpdate()},o.getExecuteResult=function(){var t=o.getQueryResult();return o.startQuerySubscription(),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;return(e||r!==this.previousData.query)&&(this.removeQuerySubscription(),this.previousData.query=r),this.updateObservableQuery(),this.isMounted&&this.startQuerySubscription(),this.getExecuteSsrResult()||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(){if(this.getOptions().skip)return!1;var t=this.getOptions(),r=(t.children,t.ssr),i=(t.displayName,t.skip,t.onCompleted,t.onError,t.partialRefetch,(0,e.__rest)(t,["children","ssr","displayName","skip","onCompleted","onError","partialRefetch"])),s=i.fetchPolicy;if(!1===r)return!1;"network-only"!==s&&"cache-and-network"!==s||(s="cache-first");var o=this.refreshClient().client.watchQuery((0,e.__assign)({},i,{fetchPolicy:s}));return this.context&&this.context.renderPromises&&this.context.renderPromises.registerSSRObservable(o,this.getOptions()),!!this.currentObservable.query.getCurrentResult().loading&&o.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(){var t,e={loading:!0,networkStatus:i.NetworkStatus.loading,called:!0,data:{}};return this.context&&this.context.renderPromises&&((t=this.context.renderPromises.addQueryPromise(this,this.getExecuteResult))||(t=e)),t},o.prototype.prepareObservableQueryOptions=function(){this.verifyDocumentType(this.getOptions().query,t.DocumentType.Query);var r=this.getOptions().displayName||"Query";return(0,e.__assign)({},this.getOptions(),{displayName:r,context:this.getOptions().context||{},metadata:{reactComponent:{displayName:r}}})},o.prototype.observableQueryFields=function(t){return{variables:t.variables,refetch:t.refetch.bind(t),fetchMore:t.fetchMore.bind(t),updateQuery:t.updateQuery.bind(t),startPolling:t.startPolling.bind(t),stopPolling:t.stopPolling.bind(t),subscribeToMore:t.subscribeToMore.bind(t)}},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)}},o.prototype.updateObservableQuery=function(){this.currentObservable.query||this.initializeObservableQuery();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(){}))},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,i=e.networkStatus,o=e.data;t.previousData.result&&t.previousData.result.loading===r&&t.previousData.result.networkStatus===i&&(0,s.equal)(t.previousData.result.data,o||{})||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={data:Object.create(null)};if(Object.assign(t,this.observableQueryFields(this.currentObservable.query)),this.getOptions().skip)t=(0,e.__assign)({},t,{data:void 0,error:void 0,loading:!1,called:!0});else{var r=this.currentObservable.query.getCurrentResult(),s=r.loading,o=r.partial,n=r.networkStatus,u=r.errors,a=r.error,p=r.data;if(p=p||Object.create(null),u&&u.length>0&&(a=new i.ApolloError({graphQLErrors:u})),Object.assign(t,{loading:s,networkStatus:n,error:a,called:!0}),s){var c=this.previousData.result?this.previousData.result.data:{};Object.assign(t.data,c,p)}else if(a)Object.assign(t,{data:(this.currentObservable.query.getLastResult()||{}).data});else{var l=this.currentObservable.query.options.fetchPolicy;if(this.getOptions().partialRefetch&&0===Object.keys(p).length&&o&&"cache-only"!==l)return Object.assign(t,{loading:!0,networkStatus:i.NetworkStatus.loading}),t.refetch(),t;Object.assign(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,p=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):p&&i&&p(i)}},o.prototype.removeQuerySubscription=function(){this.currentObservable.subscription&&(this.currentObservable.subscription.unsubscribe(),delete this.currentObservable.subscription)},o}(n);function a(i,o,n){void 0===n&&(n=!1);var a=(0,r.useContext)((0,t.getApolloContext)()),p=(0,r.useReducer)(function(t){return t+1},0),c=p[0],l=p[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,d,f,g=(y=function(){return n?v.executeLazy():v.execute()},d={options:h,context:a,tick:c},(f=(0,r.useRef)()).current&&(0,s.equal)(d,f.current.key)||(f.current={key:d,value:y()}),f.current.value);return(0,r.useEffect)(function(){return v.afterExecute({lazy:n})},[g]),(0,r.useEffect)(function(){return function(){return v.cleanup()}},[]),g}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),[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,p=r.awaitRefetchQueries,c=void 0!==p&&p,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:c,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 c=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){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.endSubscription(),delete this.currentObservable.query,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||(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; |
@@ -221,3 +221,6 @@ import { parser, operationName, DocumentType, getApolloContext } from '@apollo/react-common'; | ||
throw error; | ||
_this.forceUpdate(); | ||
if (!equal(error, _this.previousData.error)) { | ||
_this.previousData.error = error; | ||
_this.forceUpdate(); | ||
} | ||
} | ||
@@ -224,0 +227,0 @@ }); |
@@ -310,3 +310,7 @@ (function (global, factory) { | ||
_this.forceUpdate(); | ||
if (!(0, _equality.equal)(error, _this.previousData.error)) { | ||
_this.previousData.error = error; | ||
_this.forceUpdate(); | ||
} | ||
} | ||
@@ -313,0 +317,0 @@ }); |
/// <reference types="zen-observable" /> | ||
import { ReactNode } from 'react'; | ||
import { ApolloClient, ApolloQueryResult, ObservableQuery } from 'apollo-client'; | ||
import { ApolloClient, ApolloQueryResult, ObservableQuery, ApolloError } from 'apollo-client'; | ||
import { Observable } from 'apollo-link'; | ||
@@ -27,2 +27,3 @@ import { OperationVariables, QueryFunctionOptions, QueryResult, BaseMutationOptions, MutationResult, MutationFunctionOptions, ExecutionResult, BaseSubscriptionOptions, SubscriptionResult, Context } from '@apollo/react-common'; | ||
options?: QueryOptions<TData, TVariables>; | ||
error?: ApolloError; | ||
} | ||
@@ -44,3 +45,3 @@ export interface QueryCurrentObservable<TData, TVariables> { | ||
} | ||
export declare type MutationTuple<TData, TVariables> = [(options?: MutationFunctionOptions<TData, TVariables>) => Promise<void | ExecutionResult<TData>>, MutationResult<TData>]; | ||
export declare type MutationTuple<TData, TVariables> = [(options?: MutationFunctionOptions<TData, TVariables>) => Promise<ExecutionResult<TData>>, MutationResult<TData>]; | ||
export interface SubscriptionHookOptions<TData = any, TVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> { | ||
@@ -47,0 +48,0 @@ subscription?: DocumentNode; |
{ | ||
"name": "@apollo/react-hooks", | ||
"description": "React Apollo Hooks.", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"author": "opensource@apollographql.com", | ||
@@ -39,3 +39,4 @@ "keywords": [ | ||
"peerDependencies": { | ||
"apollo-client": "^2.6.3", | ||
"@types/react": "^16.8.0", | ||
"apollo-client": "^2.6.4", | ||
"graphql": "^14.3.1", | ||
@@ -46,3 +47,3 @@ "react": "^16.8.0", | ||
"dependencies": { | ||
"@apollo/react-common": "^3.0.0", | ||
"@apollo/react-common": "^3.0.1", | ||
"@wry/equality": "^0.1.9", | ||
@@ -60,7 +61,7 @@ "ts-invariant": "^0.4.4", | ||
"jest": "24.8.0", | ||
"rollup": "1.18.0", | ||
"tsc-watch": "2.2.1", | ||
"rollup": "1.19.4", | ||
"tsc-watch": "2.4.0", | ||
"typescript": "3.5.3" | ||
}, | ||
"gitHead": "ffdae346e8fa89a519c4fa0a3df5ab71ff77aa97" | ||
"gitHead": "ec4208c20750a8eb605bda2f9f0ffb44fb4723b0" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
348515
3203
9
Updated@apollo/react-common@^3.0.1