@apollo/react-hooks
Advanced tools
Comparing version 3.1.1 to 3.1.2-beta.1
@@ -13,3 +13,3 @@ import { ApolloClient } from 'apollo-client'; | ||
getOptions(): CommonOptions<TOptions>; | ||
setOptions(newOptions: CommonOptions<TOptions>): void; | ||
setOptions(newOptions: CommonOptions<TOptions>, storePrevious?: boolean): void; | ||
abstract execute(...args: any): any; | ||
@@ -16,0 +16,0 @@ abstract afterExecute(...args: any): void | (() => void); |
@@ -16,4 +16,5 @@ import { equal as isEqual } from '@wry/equality'; | ||
}; | ||
OperationData.prototype.setOptions = function (newOptions) { | ||
if (!isEqual(this.options, newOptions)) { | ||
OperationData.prototype.setOptions = function (newOptions, storePrevious) { | ||
if (storePrevious === void 0) { storePrevious = false; } | ||
if (storePrevious && !isEqual(this.options, newOptions)) { | ||
this.previousOptions = this.options; | ||
@@ -20,0 +21,0 @@ } |
@@ -46,3 +46,3 @@ import * as tslib_1 from "tslib"; | ||
this.refreshClient(); | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query, ssr = _a.ssr; | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query; | ||
if (skip || query !== this.previousData.query) { | ||
@@ -55,4 +55,3 @@ this.removeQuerySubscription(); | ||
this.startQuerySubscription(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
}; | ||
@@ -91,2 +90,3 @@ QueryData.prototype.executeLazy = function () { | ||
} | ||
this.previousOptions = this.getOptions(); | ||
return this.unmount.bind(this); | ||
@@ -101,25 +101,28 @@ }; | ||
var options = _super.prototype.getOptions.call(this); | ||
var lazyOptions = this.lazyOptions || {}; | ||
var updatedOptions = tslib_1.__assign({}, options, { variables: tslib_1.__assign({}, options.variables, lazyOptions.variables), context: tslib_1.__assign({}, options.context, lazyOptions.context) }); | ||
if (this.lazyOptions) { | ||
options.variables = tslib_1.__assign({}, options.variables, this.lazyOptions.variables); | ||
options.context = tslib_1.__assign({}, options.context, this.lazyOptions.context); | ||
} | ||
if (this.runLazy) { | ||
delete updatedOptions.skip; | ||
delete options.skip; | ||
} | ||
return updatedOptions; | ||
return options; | ||
}; | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
var treeRenderingInitiated = this.context && this.context.renderPromises; | ||
var ssrDisabled = this.getOptions().ssr === false; | ||
var fetchDisabled = this.refreshClient().client.disableNetworkFetches; | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (ssrDisabled && (treeRenderingInitiated || fetchDisabled)) { | ||
return ssrLoading; | ||
} | ||
var result; | ||
if (this.context && this.context.renderPromises) { | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (ssrDisabled) { | ||
return ssrLoading; | ||
} | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult); | ||
if (!result) { | ||
result = ssrLoading; | ||
} | ||
if (treeRenderingInitiated) { | ||
result = | ||
this.context.renderPromises.addQueryPromise(this, this.getExecuteResult) || ssrLoading; | ||
} | ||
@@ -138,3 +141,3 @@ return result; | ||
} | ||
return tslib_1.__assign({}, options, { displayName: displayName, context: options.context || {}, metadata: { reactComponent: { displayName: displayName } } }); | ||
return tslib_1.__assign({}, options, { displayName: displayName, context: options.context, metadata: { reactComponent: { displayName: displayName } } }); | ||
}; | ||
@@ -148,3 +151,3 @@ QueryData.prototype.initializeObservableQuery = function () { | ||
this.previousData.observableQueryOptions = tslib_1.__assign({}, observableQueryOptions, { children: null }); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(tslib_1.__assign({}, observableQueryOptions)); | ||
if (this.context && this.context.renderPromises) { | ||
@@ -151,0 +154,0 @@ this.context.renderPromises.registerSSRObservable(this.currentObservable.query, observableQueryOptions); |
@@ -44,4 +44,8 @@ exports.__esModule = true; | ||
OperationData.prototype.setOptions = function (newOptions) { | ||
if (!(0, _equality.equal)(this.options, newOptions)) { | ||
OperationData.prototype.setOptions = function (newOptions, storePrevious) { | ||
if (storePrevious === void 0) { | ||
storePrevious = false; | ||
} | ||
if (storePrevious && !(0, _equality.equal)(this.options, newOptions)) { | ||
this.previousOptions = this.options; | ||
@@ -148,4 +152,3 @@ } | ||
skip = _a.skip, | ||
query = _a.query, | ||
ssr = _a.ssr; | ||
query = _a.query; | ||
@@ -159,4 +162,3 @@ if (skip || query !== this.previousData.query) { | ||
if (this.isMounted) this.startQuerySubscription(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
}; | ||
@@ -195,2 +197,3 @@ | ||
this.previousOptions = this.getOptions(); | ||
return this.unmount.bind(this); | ||
@@ -208,35 +211,33 @@ }; | ||
var lazyOptions = this.lazyOptions || {}; | ||
var updatedOptions = (0, _tslib.__assign)({}, options, { | ||
variables: (0, _tslib.__assign)({}, options.variables, lazyOptions.variables), | ||
context: (0, _tslib.__assign)({}, options.context, lazyOptions.context) | ||
}); | ||
if (this.lazyOptions) { | ||
options.variables = (0, _tslib.__assign)({}, options.variables, this.lazyOptions.variables); | ||
options.context = (0, _tslib.__assign)({}, options.context, this.lazyOptions.context); | ||
} | ||
if (this.runLazy) { | ||
delete updatedOptions.skip; | ||
delete options.skip; | ||
} | ||
return updatedOptions; | ||
return options; | ||
}; | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
var result; | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
var treeRenderingInitiated = this.context && this.context.renderPromises; | ||
var ssrDisabled = this.getOptions().ssr === false; | ||
var fetchDisabled = this.refreshClient().client.disableNetworkFetches; | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: _apolloClient.NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (this.context && this.context.renderPromises) { | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: _apolloClient.NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (ssrDisabled && (treeRenderingInitiated || fetchDisabled)) { | ||
return ssrLoading; | ||
} | ||
if (ssrDisabled) { | ||
return ssrLoading; | ||
} | ||
var result; | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult); | ||
if (!result) { | ||
result = ssrLoading; | ||
} | ||
if (treeRenderingInitiated) { | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult) || ssrLoading; | ||
} | ||
@@ -258,3 +259,3 @@ | ||
displayName: displayName, | ||
context: options.context || {}, | ||
context: options.context, | ||
metadata: { | ||
@@ -278,3 +279,3 @@ reactComponent: { | ||
}); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery((0, _tslib.__assign)({}, observableQueryOptions)); | ||
@@ -902,3 +903,3 @@ if (this.context && this.context.renderPromises) { | ||
var subscriptionData = getSubscriptionDataRef(); | ||
subscriptionData.setOptions(updatedOptions); | ||
subscriptionData.setOptions(updatedOptions, true); | ||
subscriptionData.context = context; | ||
@@ -905,0 +906,0 @@ (0, _react.useEffect)(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 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; | ||
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,!0),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,e){void 0===e&&(e=!1),e&&!(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;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(){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.previousOptions=this.getOptions(),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);return this.lazyOptions&&(t.variables=(0,e.__assign)({},t.variables,this.lazyOptions.variables),t.context=(0,e.__assign)({},t.context,this.lazyOptions.context)),this.runLazy&&delete t.skip,t},o.prototype.getExecuteSsrResult=function(){var t,e=this.context&&this.context.renderPromises,r=!1===this.getOptions().ssr,s=this.refreshClient().client.disableNetworkFetches,o={loading:!0,networkStatus:i.NetworkStatus.loading,called:!0,data:void 0};return r&&(e||s)?o:(e&&(t=this.context.renderPromises.addQueryPromise(this,this.getExecuteResult)||o),t)},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((0,e.__assign)({},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 y,f,d,g={options:(0,e.__assign)({},h,{onError:void 0,onCompleted:void 0}),context:u,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})},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; |
@@ -21,4 +21,5 @@ import { parser, operationName, DocumentType, getApolloContext } from '@apollo/react-common'; | ||
}; | ||
OperationData.prototype.setOptions = function (newOptions) { | ||
if (!equal(this.options, newOptions)) { | ||
OperationData.prototype.setOptions = function (newOptions, storePrevious) { | ||
if (storePrevious === void 0) { storePrevious = false; } | ||
if (storePrevious && !equal(this.options, newOptions)) { | ||
this.previousOptions = this.options; | ||
@@ -98,3 +99,3 @@ } | ||
this.refreshClient(); | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query, ssr = _a.ssr; | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query; | ||
if (skip || query !== this.previousData.query) { | ||
@@ -107,4 +108,3 @@ this.removeQuerySubscription(); | ||
this.startQuerySubscription(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
}; | ||
@@ -143,2 +143,3 @@ QueryData.prototype.executeLazy = function () { | ||
} | ||
this.previousOptions = this.getOptions(); | ||
return this.unmount.bind(this); | ||
@@ -153,25 +154,28 @@ }; | ||
var options = _super.prototype.getOptions.call(this); | ||
var lazyOptions = this.lazyOptions || {}; | ||
var updatedOptions = __assign({}, options, { variables: __assign({}, options.variables, lazyOptions.variables), context: __assign({}, options.context, lazyOptions.context) }); | ||
if (this.lazyOptions) { | ||
options.variables = __assign({}, options.variables, this.lazyOptions.variables); | ||
options.context = __assign({}, options.context, this.lazyOptions.context); | ||
} | ||
if (this.runLazy) { | ||
delete updatedOptions.skip; | ||
delete options.skip; | ||
} | ||
return updatedOptions; | ||
return options; | ||
}; | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
var treeRenderingInitiated = this.context && this.context.renderPromises; | ||
var ssrDisabled = this.getOptions().ssr === false; | ||
var fetchDisabled = this.refreshClient().client.disableNetworkFetches; | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (ssrDisabled && (treeRenderingInitiated || fetchDisabled)) { | ||
return ssrLoading; | ||
} | ||
var result; | ||
if (this.context && this.context.renderPromises) { | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (ssrDisabled) { | ||
return ssrLoading; | ||
} | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult); | ||
if (!result) { | ||
result = ssrLoading; | ||
} | ||
if (treeRenderingInitiated) { | ||
result = | ||
this.context.renderPromises.addQueryPromise(this, this.getExecuteResult) || ssrLoading; | ||
} | ||
@@ -190,3 +194,3 @@ return result; | ||
} | ||
return __assign({}, options, { displayName: displayName, context: options.context || {}, metadata: { reactComponent: { displayName: displayName } } }); | ||
return __assign({}, options, { displayName: displayName, context: options.context, metadata: { reactComponent: { displayName: displayName } } }); | ||
}; | ||
@@ -200,3 +204,3 @@ QueryData.prototype.initializeObservableQuery = function () { | ||
this.previousData.observableQueryOptions = __assign({}, observableQueryOptions, { children: null }); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(__assign({}, observableQueryOptions)); | ||
if (this.context && this.context.renderPromises) { | ||
@@ -679,3 +683,3 @@ this.context.renderPromises.registerSSRObservable(this.currentObservable.query, observableQueryOptions); | ||
var subscriptionData = getSubscriptionDataRef(); | ||
subscriptionData.setOptions(updatedOptions); | ||
subscriptionData.setOptions(updatedOptions, true); | ||
subscriptionData.context = context; | ||
@@ -682,0 +686,0 @@ useEffect(function () { return subscriptionData.afterExecute(); }); |
@@ -46,4 +46,8 @@ (function (global, factory) { | ||
OperationData.prototype.setOptions = function (newOptions) { | ||
if (!(0, _equality.equal)(this.options, newOptions)) { | ||
OperationData.prototype.setOptions = function (newOptions, storePrevious) { | ||
if (storePrevious === void 0) { | ||
storePrevious = false; | ||
} | ||
if (storePrevious && !(0, _equality.equal)(this.options, newOptions)) { | ||
this.previousOptions = this.options; | ||
@@ -150,4 +154,3 @@ } | ||
skip = _a.skip, | ||
query = _a.query, | ||
ssr = _a.ssr; | ||
query = _a.query; | ||
@@ -161,4 +164,3 @@ if (skip || query !== this.previousData.query) { | ||
if (this.isMounted) this.startQuerySubscription(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
}; | ||
@@ -197,2 +199,3 @@ | ||
this.previousOptions = this.getOptions(); | ||
return this.unmount.bind(this); | ||
@@ -210,35 +213,33 @@ }; | ||
var lazyOptions = this.lazyOptions || {}; | ||
var updatedOptions = (0, _tslib.__assign)({}, options, { | ||
variables: (0, _tslib.__assign)({}, options.variables, lazyOptions.variables), | ||
context: (0, _tslib.__assign)({}, options.context, lazyOptions.context) | ||
}); | ||
if (this.lazyOptions) { | ||
options.variables = (0, _tslib.__assign)({}, options.variables, this.lazyOptions.variables); | ||
options.context = (0, _tslib.__assign)({}, options.context, this.lazyOptions.context); | ||
} | ||
if (this.runLazy) { | ||
delete updatedOptions.skip; | ||
delete options.skip; | ||
} | ||
return updatedOptions; | ||
return options; | ||
}; | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
var result; | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
var treeRenderingInitiated = this.context && this.context.renderPromises; | ||
var ssrDisabled = this.getOptions().ssr === false; | ||
var fetchDisabled = this.refreshClient().client.disableNetworkFetches; | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: _apolloClient.NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (this.context && this.context.renderPromises) { | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: _apolloClient.NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
if (ssrDisabled && (treeRenderingInitiated || fetchDisabled)) { | ||
return ssrLoading; | ||
} | ||
if (ssrDisabled) { | ||
return ssrLoading; | ||
} | ||
var result; | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult); | ||
if (!result) { | ||
result = ssrLoading; | ||
} | ||
if (treeRenderingInitiated) { | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult) || ssrLoading; | ||
} | ||
@@ -260,3 +261,3 @@ | ||
displayName: displayName, | ||
context: options.context || {}, | ||
context: options.context, | ||
metadata: { | ||
@@ -280,3 +281,3 @@ reactComponent: { | ||
}); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
this.currentObservable.query = this.refreshClient().client.watchQuery((0, _tslib.__assign)({}, observableQueryOptions)); | ||
@@ -904,3 +905,3 @@ if (this.context && this.context.renderPromises) { | ||
var subscriptionData = getSubscriptionDataRef(); | ||
subscriptionData.setOptions(updatedOptions); | ||
subscriptionData.setOptions(updatedOptions, true); | ||
subscriptionData.context = context; | ||
@@ -907,0 +908,0 @@ (0, _react.useEffect)(function () { |
@@ -26,3 +26,3 @@ import * as tslib_1 from "tslib"; | ||
var subscriptionData = getSubscriptionDataRef(); | ||
subscriptionData.setOptions(updatedOptions); | ||
subscriptionData.setOptions(updatedOptions, true); | ||
subscriptionData.context = context; | ||
@@ -29,0 +29,0 @@ useEffect(function () { return subscriptionData.afterExecute(); }); |
{ | ||
"name": "@apollo/react-hooks", | ||
"description": "React Apollo Hooks.", | ||
"version": "3.1.1", | ||
"version": "3.1.2-beta.1", | ||
"author": "opensource@apollographql.com", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"predeploy": "npm run build", | ||
"deploy": "npm publish", | ||
"deploy": "npm publish --tag beta", | ||
"test": "npx jest --config ../../config/jest.config.js --testPathPattern packages/hooks", | ||
@@ -47,3 +47,3 @@ "test:watch": "npx jest --config ../../config/jest.config.js --testPathPattern packages/hooks --watch", | ||
"dependencies": { | ||
"@apollo/react-common": "^3.1.1", | ||
"@apollo/react-common": "^3.1.2-beta.1", | ||
"@wry/equality": "^0.1.9", | ||
@@ -61,7 +61,7 @@ "ts-invariant": "^0.4.4", | ||
"jest": "24.9.0", | ||
"rollup": "1.20.3", | ||
"tsc-watch": "3.0.1", | ||
"typescript": "3.5.3" | ||
"rollup": "1.21.4", | ||
"tsc-watch": "3.0.2", | ||
"typescript": "3.6.3" | ||
}, | ||
"gitHead": "1ad1e76c298b8c8ff9a49c03a8dec4b1da812625" | ||
"gitHead": "d67d00cd517905559084b2a9aefa04c8f6e06764" | ||
} |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
373727
3405
3