@apollo/react-hooks
Advanced tools
Comparing version 3.1.0-beta.0 to 3.1.0
@@ -35,2 +35,3 @@ import * as tslib_1 from "tslib"; | ||
this.verifyDocumentType(this.getOptions().mutation, DocumentType.Mutation); | ||
result.client = this.refreshClient().client; | ||
return [this.runMutation, result]; | ||
@@ -37,0 +38,0 @@ }; |
@@ -28,3 +28,2 @@ import { ApolloQueryResult } from 'apollo-client'; | ||
private prepareObservableQueryOptions; | ||
private observableQueryFields; | ||
private initializeObservableQuery; | ||
@@ -37,2 +36,9 @@ private updateObservableQuery; | ||
private removeQuerySubscription; | ||
private obsRefetch; | ||
private obsFetchMore; | ||
private obsUpdateQuery; | ||
private obsStartPolling; | ||
private obsStopPolling; | ||
private obsSubscribeToMore; | ||
private observableQueryFields; | ||
} |
@@ -15,2 +15,3 @@ import * as tslib_1 from "tslib"; | ||
_this.runLazyQuery = function (options) { | ||
_this.cleanup(); | ||
_this.runLazy = true; | ||
@@ -25,2 +26,12 @@ _this.lazyOptions = options; | ||
}; | ||
_this.obsRefetch = function (variables) { | ||
return _this.currentObservable.query.refetch(variables); | ||
}; | ||
_this.obsFetchMore = function (fetchMoreOptions) { return _this.currentObservable.query.fetchMore(fetchMoreOptions); }; | ||
_this.obsUpdateQuery = function (mapFn) { return _this.currentObservable.query.updateQuery(mapFn); }; | ||
_this.obsStartPolling = function (pollInterval) { | ||
return _this.currentObservable.query.startPolling(pollInterval); | ||
}; | ||
_this.obsStopPolling = function () { return _this.currentObservable.query.stopPolling(); }; | ||
_this.obsSubscribeToMore = function (options) { return _this.currentObservable.query.subscribeToMore(options); }; | ||
_this.forceUpdate = forceUpdate; | ||
@@ -31,3 +42,3 @@ return _this; | ||
this.refreshClient(); | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query; | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query, ssr = _a.ssr; | ||
if (skip || query !== this.previousData.query) { | ||
@@ -40,3 +51,4 @@ this.removeQuerySubscription(); | ||
this.startQuerySubscription(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
}; | ||
@@ -57,16 +69,7 @@ QueryData.prototype.executeLazy = function () { | ||
QueryData.prototype.fetchData = function () { | ||
if (this.getOptions().skip) | ||
var options = this.getOptions(); | ||
if (options.skip || options.ssr === false) | ||
return false; | ||
var _a = this.getOptions(), children = _a.children, ssr = _a.ssr, displayName = _a.displayName, skip = _a.skip, onCompleted = _a.onCompleted, onError = _a.onError, partialRefetch = _a.partialRefetch, opts = tslib_1.__rest(_a, ["children", "ssr", "displayName", "skip", "onCompleted", "onError", "partialRefetch"]); | ||
var fetchPolicy = opts.fetchPolicy; | ||
if (ssr === false) | ||
return false; | ||
if (fetchPolicy === 'network-only' || fetchPolicy === 'cache-and-network') { | ||
fetchPolicy = 'cache-first'; | ||
} | ||
var obs = this.refreshClient().client.watchQuery(tslib_1.__assign({}, opts, { fetchPolicy: fetchPolicy })); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(obs, this.getOptions()); | ||
} | ||
var currentResult = this.currentObservable.query.getCurrentResult(); | ||
var obs = this.currentObservable.query; | ||
var currentResult = obs.getCurrentResult(); | ||
return currentResult.loading ? obs.result() : false; | ||
@@ -101,11 +104,14 @@ }; | ||
}; | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
var result; | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
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); | ||
@@ -119,17 +125,13 @@ if (!result) { | ||
QueryData.prototype.prepareObservableQueryOptions = function () { | ||
this.verifyDocumentType(this.getOptions().query, DocumentType.Query); | ||
var displayName = this.getOptions().displayName || 'Query'; | ||
return tslib_1.__assign({}, this.getOptions(), { displayName: displayName, context: this.getOptions().context || {}, metadata: { reactComponent: { displayName: displayName } } }); | ||
var options = this.getOptions(); | ||
this.verifyDocumentType(options.query, DocumentType.Query); | ||
var displayName = options.displayName || 'Query'; | ||
if (this.context && | ||
this.context.renderPromises && | ||
(options.fetchPolicy === 'network-only' || | ||
options.fetchPolicy === 'cache-and-network')) { | ||
options.fetchPolicy = 'cache-first'; | ||
} | ||
return tslib_1.__assign({}, options, { displayName: displayName, context: options.context || {}, metadata: { reactComponent: { displayName: displayName } } }); | ||
}; | ||
QueryData.prototype.observableQueryFields = function (observable) { | ||
return { | ||
variables: observable.variables, | ||
refetch: observable.refetch.bind(observable), | ||
fetchMore: observable.fetchMore.bind(observable), | ||
updateQuery: observable.updateQuery.bind(observable), | ||
startPolling: observable.startPolling.bind(observable), | ||
stopPolling: observable.stopPolling.bind(observable), | ||
subscribeToMore: observable.subscribeToMore.bind(observable) | ||
}; | ||
}; | ||
QueryData.prototype.initializeObservableQuery = function () { | ||
@@ -143,2 +145,5 @@ if (this.context && this.context.renderPromises) { | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(this.currentObservable.query, observableQueryOptions); | ||
} | ||
} | ||
@@ -149,2 +154,3 @@ }; | ||
this.initializeObservableQuery(); | ||
return; | ||
} | ||
@@ -167,7 +173,14 @@ var newObservableQueryOptions = tslib_1.__assign({}, this.prepareObservableQueryOptions(), { children: null }); | ||
var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data; | ||
if (_this.previousData.result && | ||
_this.previousData.result.loading === loading && | ||
_this.previousData.result.networkStatus === networkStatus && | ||
isEqual(_this.previousData.result.data, data)) { | ||
return; | ||
var previousResult = _this.previousData.result; | ||
if (previousResult) { | ||
if (previousResult.loading && | ||
previousResult.networkStatus === NetworkStatus.fetchMore && | ||
isEqual(previousResult.data, data)) { | ||
return; | ||
} | ||
if (previousResult.loading === loading && | ||
previousResult.networkStatus === networkStatus && | ||
isEqual(previousResult.data, data)) { | ||
return; | ||
} | ||
} | ||
@@ -199,4 +212,5 @@ _this.forceUpdate(); | ||
QueryData.prototype.getQueryResult = function () { | ||
var result = tslib_1.__assign({}, this.observableQueryFields(this.currentObservable.query)); | ||
if (this.getOptions().skip) { | ||
var result = this.observableQueryFields(); | ||
var options = this.getOptions(); | ||
if (options.skip) { | ||
result = tslib_1.__assign({}, result, { data: undefined, error: undefined, loading: false, called: true }); | ||
@@ -228,3 +242,3 @@ } | ||
var fetchPolicy = this.currentObservable.query.options.fetchPolicy; | ||
var partialRefetch = this.getOptions().partialRefetch; | ||
var partialRefetch = options.partialRefetch; | ||
if (partialRefetch && | ||
@@ -274,2 +288,14 @@ !data && | ||
}; | ||
QueryData.prototype.observableQueryFields = function () { | ||
var observable = this.currentObservable.query; | ||
return { | ||
variables: observable.variables, | ||
refetch: this.obsRefetch, | ||
fetchMore: this.obsFetchMore, | ||
updateQuery: this.obsUpdateQuery, | ||
startPolling: this.obsStartPolling, | ||
stopPolling: this.obsStopPolling, | ||
subscribeToMore: this.obsSubscribeToMore | ||
}; | ||
}; | ||
return QueryData; | ||
@@ -276,0 +302,0 @@ }(OperationData)); |
@@ -15,2 +15,11 @@ import * as tslib_1 from "tslib"; | ||
SubscriptionData.prototype.execute = function (result) { | ||
if (this.getOptions().skip === true) { | ||
this.cleanup(); | ||
return { | ||
loading: false, | ||
error: undefined, | ||
data: undefined, | ||
variables: this.getOptions().variables | ||
}; | ||
} | ||
var currentResult = result; | ||
@@ -28,5 +37,5 @@ if (this.refreshClient().isNew) { | ||
(this.previousOptions.subscription !== this.getOptions().subscription || | ||
!isEqual(this.previousOptions.variables, this.getOptions().variables))) { | ||
this.endSubscription(); | ||
delete this.currentObservable.query; | ||
!isEqual(this.previousOptions.variables, this.getOptions().variables) || | ||
this.previousOptions.skip !== this.getOptions().skip)) { | ||
this.cleanup(); | ||
currentResult = this.getLoadingResult(); | ||
@@ -47,3 +56,3 @@ } | ||
SubscriptionData.prototype.initialize = function (options) { | ||
if (this.currentObservable.query) | ||
if (this.currentObservable.query || this.getOptions().skip === true) | ||
return; | ||
@@ -50,0 +59,0 @@ this.currentObservable.query = this.refreshClient().client.subscribe({ |
@@ -96,2 +96,4 @@ exports.__esModule = true; | ||
_this.runLazyQuery = function (options) { | ||
_this.cleanup(); | ||
_this.runLazy = true; | ||
@@ -111,2 +113,26 @@ _this.lazyOptions = options; | ||
_this.obsRefetch = function (variables) { | ||
return _this.currentObservable.query.refetch(variables); | ||
}; | ||
_this.obsFetchMore = function (fetchMoreOptions) { | ||
return _this.currentObservable.query.fetchMore(fetchMoreOptions); | ||
}; | ||
_this.obsUpdateQuery = function (mapFn) { | ||
return _this.currentObservable.query.updateQuery(mapFn); | ||
}; | ||
_this.obsStartPolling = function (pollInterval) { | ||
return _this.currentObservable.query.startPolling(pollInterval); | ||
}; | ||
_this.obsStopPolling = function () { | ||
return _this.currentObservable.query.stopPolling(); | ||
}; | ||
_this.obsSubscribeToMore = function (options) { | ||
return _this.currentObservable.query.subscribeToMore(options); | ||
}; | ||
_this.forceUpdate = forceUpdate; | ||
@@ -121,3 +147,4 @@ return _this; | ||
skip = _a.skip, | ||
query = _a.query; | ||
query = _a.query, | ||
ssr = _a.ssr; | ||
@@ -131,3 +158,4 @@ if (skip || query !== this.previousData.query) { | ||
if (this.isMounted) this.startQuerySubscription(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
}; | ||
@@ -145,30 +173,6 @@ | ||
QueryData.prototype.fetchData = function () { | ||
if (this.getOptions().skip) return false; | ||
var _a = this.getOptions(), | ||
children = _a.children, | ||
ssr = _a.ssr, | ||
displayName = _a.displayName, | ||
skip = _a.skip, | ||
onCompleted = _a.onCompleted, | ||
onError = _a.onError, | ||
partialRefetch = _a.partialRefetch, | ||
opts = (0, _tslib.__rest)(_a, ["children", "ssr", "displayName", "skip", "onCompleted", "onError", "partialRefetch"]); | ||
var fetchPolicy = opts.fetchPolicy; | ||
if (ssr === false) return false; | ||
if (fetchPolicy === 'network-only' || fetchPolicy === 'cache-and-network') { | ||
fetchPolicy = 'cache-first'; | ||
} | ||
var obs = this.refreshClient().client.watchQuery((0, _tslib.__assign)({}, opts, { | ||
fetchPolicy: fetchPolicy | ||
})); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(obs, this.getOptions()); | ||
} | ||
var currentResult = this.currentObservable.query.getCurrentResult(); | ||
var options = this.getOptions(); | ||
if (options.skip || options.ssr === false) return false; | ||
var obs = this.currentObservable.query; | ||
var currentResult = obs.getCurrentResult(); | ||
return currentResult.loading ? obs.result() : false; | ||
@@ -216,12 +220,17 @@ }; | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
var result; | ||
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) { | ||
return ssrLoading; | ||
} | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult); | ||
@@ -238,7 +247,13 @@ | ||
QueryData.prototype.prepareObservableQueryOptions = function () { | ||
this.verifyDocumentType(this.getOptions().query, _reactCommon.DocumentType.Query); | ||
var displayName = this.getOptions().displayName || 'Query'; | ||
return (0, _tslib.__assign)({}, this.getOptions(), { | ||
var options = this.getOptions(); | ||
this.verifyDocumentType(options.query, _reactCommon.DocumentType.Query); | ||
var displayName = options.displayName || 'Query'; | ||
if (this.context && this.context.renderPromises && (options.fetchPolicy === 'network-only' || options.fetchPolicy === 'cache-and-network')) { | ||
options.fetchPolicy = 'cache-first'; | ||
} | ||
return (0, _tslib.__assign)({}, options, { | ||
displayName: displayName, | ||
context: this.getOptions().context || {}, | ||
context: options.context || {}, | ||
metadata: { | ||
@@ -252,14 +267,2 @@ reactComponent: { | ||
QueryData.prototype.observableQueryFields = function (observable) { | ||
return { | ||
variables: observable.variables, | ||
refetch: observable.refetch.bind(observable), | ||
fetchMore: observable.fetchMore.bind(observable), | ||
updateQuery: observable.updateQuery.bind(observable), | ||
startPolling: observable.startPolling.bind(observable), | ||
stopPolling: observable.stopPolling.bind(observable), | ||
subscribeToMore: observable.subscribeToMore.bind(observable) | ||
}; | ||
}; | ||
QueryData.prototype.initializeObservableQuery = function () { | ||
@@ -276,2 +279,6 @@ if (this.context && this.context.renderPromises) { | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(this.currentObservable.query, observableQueryOptions); | ||
} | ||
} | ||
@@ -283,2 +290,3 @@ }; | ||
this.initializeObservableQuery(); | ||
return; | ||
} | ||
@@ -306,5 +314,12 @@ | ||
data = _a.data; | ||
var previousResult = _this.previousData.result; | ||
if (_this.previousData.result && _this.previousData.result.loading === loading && _this.previousData.result.networkStatus === networkStatus && (0, _equality.equal)(_this.previousData.result.data, data)) { | ||
return; | ||
if (previousResult) { | ||
if (previousResult.loading && previousResult.networkStatus === _apolloClient.NetworkStatus.fetchMore && (0, _equality.equal)(previousResult.data, data)) { | ||
return; | ||
} | ||
if (previousResult.loading === loading && previousResult.networkStatus === networkStatus && (0, _equality.equal)(previousResult.data, data)) { | ||
return; | ||
} | ||
} | ||
@@ -341,5 +356,6 @@ | ||
QueryData.prototype.getQueryResult = function () { | ||
var result = (0, _tslib.__assign)({}, this.observableQueryFields(this.currentObservable.query)); | ||
var result = this.observableQueryFields(); | ||
var options = this.getOptions(); | ||
if (this.getOptions().skip) { | ||
if (options.skip) { | ||
result = (0, _tslib.__assign)({}, result, { | ||
@@ -382,3 +398,3 @@ data: undefined, | ||
var fetchPolicy = this.currentObservable.query.options.fetchPolicy; | ||
var partialRefetch = this.getOptions().partialRefetch; | ||
var partialRefetch = options.partialRefetch; | ||
@@ -436,2 +452,15 @@ if (partialRefetch && !data && partial && fetchPolicy !== 'cache-only') { | ||
QueryData.prototype.observableQueryFields = function () { | ||
var observable = this.currentObservable.query; | ||
return { | ||
variables: observable.variables, | ||
refetch: this.obsRefetch, | ||
fetchMore: this.obsFetchMore, | ||
updateQuery: this.obsUpdateQuery, | ||
startPolling: this.obsStartPolling, | ||
stopPolling: this.obsStopPolling, | ||
subscribeToMore: this.obsSubscribeToMore | ||
}; | ||
}; | ||
return QueryData; | ||
@@ -485,3 +514,6 @@ }(OperationData); | ||
var memo = { | ||
options: updatedOptions, | ||
options: (0, _tslib.__assign)({}, updatedOptions, { | ||
onError: undefined, | ||
onCompleted: undefined | ||
}), | ||
context: context, | ||
@@ -493,2 +525,3 @@ tick: tick | ||
}, memo); | ||
var queryResult = lazy ? result[1] : result; | ||
(0, _react.useEffect)(function () { | ||
@@ -498,3 +531,3 @@ return queryData.afterExecute({ | ||
}); | ||
}, [result]); | ||
}, [queryResult.loading, queryResult.networkStatus, queryResult.error, queryResult.data]); | ||
(0, _react.useEffect)(function () { | ||
@@ -558,2 +591,3 @@ return function () { | ||
this.verifyDocumentType(this.getOptions().mutation, _reactCommon.DocumentType.Mutation); | ||
result.client = this.refreshClient().client; | ||
return [this.runMutation, result]; | ||
@@ -727,2 +761,12 @@ }; | ||
SubscriptionData.prototype.execute = function (result) { | ||
if (this.getOptions().skip === true) { | ||
this.cleanup(); | ||
return { | ||
loading: false, | ||
error: undefined, | ||
data: undefined, | ||
variables: this.getOptions().variables | ||
}; | ||
} | ||
var currentResult = result; | ||
@@ -740,5 +784,4 @@ | ||
if (shouldResubscribe !== false && this.previousOptions && Object.keys(this.previousOptions).length > 0 && (this.previousOptions.subscription !== this.getOptions().subscription || !(0, _equality.equal)(this.previousOptions.variables, this.getOptions().variables))) { | ||
this.endSubscription(); | ||
delete this.currentObservable.query; | ||
if (shouldResubscribe !== false && this.previousOptions && Object.keys(this.previousOptions).length > 0 && (this.previousOptions.subscription !== this.getOptions().subscription || !(0, _equality.equal)(this.previousOptions.variables, this.getOptions().variables) || this.previousOptions.skip !== this.getOptions().skip)) { | ||
this.cleanup(); | ||
currentResult = this.getLoadingResult(); | ||
@@ -765,3 +808,3 @@ } | ||
SubscriptionData.prototype.initialize = function (options) { | ||
if (this.currentObservable.query) return; | ||
if (this.currentObservable.query || this.getOptions().skip === true) return; | ||
this.currentObservable.query = this.refreshClient().client.subscribe({ | ||
@@ -838,5 +881,10 @@ query: options.subscription, | ||
var context = (0, _react.useContext)((0, _reactCommon.getApolloContext)()); | ||
var updatedOptions = options ? (0, _tslib.__assign)({}, options, { | ||
subscription: subscription | ||
}) : { | ||
subscription: subscription | ||
}; | ||
var _a = (0, _react.useState)({ | ||
loading: true, | ||
loading: !updatedOptions.skip, | ||
error: undefined, | ||
@@ -848,7 +896,2 @@ data: undefined | ||
var updatedOptions = options ? (0, _tslib.__assign)({}, options, { | ||
subscription: subscription | ||
}) : { | ||
subscription: subscription | ||
}; | ||
var subscriptionDataRef = (0, _react.useRef)(); | ||
@@ -855,0 +898,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:void 0};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=(0,e.__assign)({},this.observableQueryFields(this.currentObservable.query));if(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(u&&u.length>0&&(a=new i.ApolloError({graphQLErrors:u})),t=(0,e.__assign)({},t,{loading:s,networkStatus:n,error:a,called:!0}),s){var c=this.previousData.result&&this.previousData.result.data;t.data=c&&p?(0,e.__assign)({},c,p):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&&!p&&o&&"cache-only"!==l)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,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],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; |
import { parser, operationName, DocumentType, getApolloContext } from '@apollo/react-common'; | ||
export { ApolloConsumer, ApolloProvider, getApolloContext, resetApolloContext } from '@apollo/react-common'; | ||
import { __extends, __rest, __assign } from 'tslib'; | ||
import { __extends, __assign } from 'tslib'; | ||
import React, { useRef, useContext, useReducer, useEffect, useState } from 'react'; | ||
@@ -66,2 +66,3 @@ import { NetworkStatus, ApolloError } from 'apollo-client'; | ||
_this.runLazyQuery = function (options) { | ||
_this.cleanup(); | ||
_this.runLazy = true; | ||
@@ -76,2 +77,12 @@ _this.lazyOptions = options; | ||
}; | ||
_this.obsRefetch = function (variables) { | ||
return _this.currentObservable.query.refetch(variables); | ||
}; | ||
_this.obsFetchMore = function (fetchMoreOptions) { return _this.currentObservable.query.fetchMore(fetchMoreOptions); }; | ||
_this.obsUpdateQuery = function (mapFn) { return _this.currentObservable.query.updateQuery(mapFn); }; | ||
_this.obsStartPolling = function (pollInterval) { | ||
return _this.currentObservable.query.startPolling(pollInterval); | ||
}; | ||
_this.obsStopPolling = function () { return _this.currentObservable.query.stopPolling(); }; | ||
_this.obsSubscribeToMore = function (options) { return _this.currentObservable.query.subscribeToMore(options); }; | ||
_this.forceUpdate = forceUpdate; | ||
@@ -82,3 +93,3 @@ return _this; | ||
this.refreshClient(); | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query; | ||
var _a = this.getOptions(), skip = _a.skip, query = _a.query, ssr = _a.ssr; | ||
if (skip || query !== this.previousData.query) { | ||
@@ -91,3 +102,4 @@ this.removeQuerySubscription(); | ||
this.startQuerySubscription(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
}; | ||
@@ -108,16 +120,7 @@ QueryData.prototype.executeLazy = function () { | ||
QueryData.prototype.fetchData = function () { | ||
if (this.getOptions().skip) | ||
var options = this.getOptions(); | ||
if (options.skip || options.ssr === false) | ||
return false; | ||
var _a = this.getOptions(), children = _a.children, ssr = _a.ssr, displayName = _a.displayName, skip = _a.skip, onCompleted = _a.onCompleted, onError = _a.onError, partialRefetch = _a.partialRefetch, opts = __rest(_a, ["children", "ssr", "displayName", "skip", "onCompleted", "onError", "partialRefetch"]); | ||
var fetchPolicy = opts.fetchPolicy; | ||
if (ssr === false) | ||
return false; | ||
if (fetchPolicy === 'network-only' || fetchPolicy === 'cache-and-network') { | ||
fetchPolicy = 'cache-first'; | ||
} | ||
var obs = this.refreshClient().client.watchQuery(__assign({}, opts, { fetchPolicy: fetchPolicy })); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(obs, this.getOptions()); | ||
} | ||
var currentResult = this.currentObservable.query.getCurrentResult(); | ||
var obs = this.currentObservable.query; | ||
var currentResult = obs.getCurrentResult(); | ||
return currentResult.loading ? obs.result() : false; | ||
@@ -152,11 +155,14 @@ }; | ||
}; | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
var result; | ||
var ssrLoading = { | ||
loading: true, | ||
networkStatus: NetworkStatus.loading, | ||
called: true, | ||
data: undefined | ||
}; | ||
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); | ||
@@ -170,17 +176,13 @@ if (!result) { | ||
QueryData.prototype.prepareObservableQueryOptions = function () { | ||
this.verifyDocumentType(this.getOptions().query, DocumentType.Query); | ||
var displayName = this.getOptions().displayName || 'Query'; | ||
return __assign({}, this.getOptions(), { displayName: displayName, context: this.getOptions().context || {}, metadata: { reactComponent: { displayName: displayName } } }); | ||
var options = this.getOptions(); | ||
this.verifyDocumentType(options.query, DocumentType.Query); | ||
var displayName = options.displayName || 'Query'; | ||
if (this.context && | ||
this.context.renderPromises && | ||
(options.fetchPolicy === 'network-only' || | ||
options.fetchPolicy === 'cache-and-network')) { | ||
options.fetchPolicy = 'cache-first'; | ||
} | ||
return __assign({}, options, { displayName: displayName, context: options.context || {}, metadata: { reactComponent: { displayName: displayName } } }); | ||
}; | ||
QueryData.prototype.observableQueryFields = function (observable) { | ||
return { | ||
variables: observable.variables, | ||
refetch: observable.refetch.bind(observable), | ||
fetchMore: observable.fetchMore.bind(observable), | ||
updateQuery: observable.updateQuery.bind(observable), | ||
startPolling: observable.startPolling.bind(observable), | ||
stopPolling: observable.stopPolling.bind(observable), | ||
subscribeToMore: observable.subscribeToMore.bind(observable) | ||
}; | ||
}; | ||
QueryData.prototype.initializeObservableQuery = function () { | ||
@@ -194,2 +196,5 @@ if (this.context && this.context.renderPromises) { | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(this.currentObservable.query, observableQueryOptions); | ||
} | ||
} | ||
@@ -200,2 +205,3 @@ }; | ||
this.initializeObservableQuery(); | ||
return; | ||
} | ||
@@ -218,7 +224,14 @@ var newObservableQueryOptions = __assign({}, this.prepareObservableQueryOptions(), { children: null }); | ||
var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data; | ||
if (_this.previousData.result && | ||
_this.previousData.result.loading === loading && | ||
_this.previousData.result.networkStatus === networkStatus && | ||
equal(_this.previousData.result.data, data)) { | ||
return; | ||
var previousResult = _this.previousData.result; | ||
if (previousResult) { | ||
if (previousResult.loading && | ||
previousResult.networkStatus === NetworkStatus.fetchMore && | ||
equal(previousResult.data, data)) { | ||
return; | ||
} | ||
if (previousResult.loading === loading && | ||
previousResult.networkStatus === networkStatus && | ||
equal(previousResult.data, data)) { | ||
return; | ||
} | ||
} | ||
@@ -250,4 +263,5 @@ _this.forceUpdate(); | ||
QueryData.prototype.getQueryResult = function () { | ||
var result = __assign({}, this.observableQueryFields(this.currentObservable.query)); | ||
if (this.getOptions().skip) { | ||
var result = this.observableQueryFields(); | ||
var options = this.getOptions(); | ||
if (options.skip) { | ||
result = __assign({}, result, { data: undefined, error: undefined, loading: false, called: true }); | ||
@@ -279,3 +293,3 @@ } | ||
var fetchPolicy = this.currentObservable.query.options.fetchPolicy; | ||
var partialRefetch = this.getOptions().partialRefetch; | ||
var partialRefetch = options.partialRefetch; | ||
if (partialRefetch && | ||
@@ -325,2 +339,14 @@ !data && | ||
}; | ||
QueryData.prototype.observableQueryFields = function () { | ||
var observable = this.currentObservable.query; | ||
return { | ||
variables: observable.variables, | ||
refetch: this.obsRefetch, | ||
fetchMore: this.obsFetchMore, | ||
updateQuery: this.obsUpdateQuery, | ||
startPolling: this.obsStartPolling, | ||
stopPolling: this.obsStopPolling, | ||
subscribeToMore: this.obsSubscribeToMore | ||
}; | ||
}; | ||
return QueryData; | ||
@@ -354,3 +380,3 @@ }(OperationData)); | ||
var memo = { | ||
options: updatedOptions, | ||
options: __assign({}, updatedOptions, { onError: undefined, onCompleted: undefined }), | ||
context: context, | ||
@@ -360,3 +386,11 @@ tick: tick | ||
var result = useDeepMemo(function () { return (lazy ? queryData.executeLazy() : queryData.execute()); }, memo); | ||
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [result]); | ||
var queryResult = lazy | ||
? result[1] | ||
: result; | ||
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [ | ||
queryResult.loading, | ||
queryResult.networkStatus, | ||
queryResult.error, | ||
queryResult.data | ||
]); | ||
useEffect(function () { | ||
@@ -405,2 +439,3 @@ return function () { return queryData.cleanup(); }; | ||
this.verifyDocumentType(this.getOptions().mutation, DocumentType.Mutation); | ||
result.client = this.refreshClient().client; | ||
return [this.runMutation, result]; | ||
@@ -516,2 +551,11 @@ }; | ||
SubscriptionData.prototype.execute = function (result) { | ||
if (this.getOptions().skip === true) { | ||
this.cleanup(); | ||
return { | ||
loading: false, | ||
error: undefined, | ||
data: undefined, | ||
variables: this.getOptions().variables | ||
}; | ||
} | ||
var currentResult = result; | ||
@@ -529,5 +573,5 @@ if (this.refreshClient().isNew) { | ||
(this.previousOptions.subscription !== this.getOptions().subscription || | ||
!equal(this.previousOptions.variables, this.getOptions().variables))) { | ||
this.endSubscription(); | ||
delete this.currentObservable.query; | ||
!equal(this.previousOptions.variables, this.getOptions().variables) || | ||
this.previousOptions.skip !== this.getOptions().skip)) { | ||
this.cleanup(); | ||
currentResult = this.getLoadingResult(); | ||
@@ -548,3 +592,3 @@ } | ||
SubscriptionData.prototype.initialize = function (options) { | ||
if (this.currentObservable.query) | ||
if (this.currentObservable.query || this.getOptions().skip === true) | ||
return; | ||
@@ -615,9 +659,9 @@ this.currentObservable.query = this.refreshClient().client.subscribe({ | ||
var context = useContext(getApolloContext()); | ||
var updatedOptions = options | ||
? __assign({}, options, { subscription: subscription }) : { subscription: subscription }; | ||
var _a = useState({ | ||
loading: true, | ||
loading: !updatedOptions.skip, | ||
error: undefined, | ||
data: undefined | ||
}), result = _a[0], setResult = _a[1]; | ||
var updatedOptions = options | ||
? __assign({}, options, { subscription: subscription }) : { subscription: subscription }; | ||
var subscriptionDataRef = useRef(); | ||
@@ -624,0 +668,0 @@ function getSubscriptionDataRef() { |
@@ -98,2 +98,4 @@ (function (global, factory) { | ||
_this.runLazyQuery = function (options) { | ||
_this.cleanup(); | ||
_this.runLazy = true; | ||
@@ -113,2 +115,26 @@ _this.lazyOptions = options; | ||
_this.obsRefetch = function (variables) { | ||
return _this.currentObservable.query.refetch(variables); | ||
}; | ||
_this.obsFetchMore = function (fetchMoreOptions) { | ||
return _this.currentObservable.query.fetchMore(fetchMoreOptions); | ||
}; | ||
_this.obsUpdateQuery = function (mapFn) { | ||
return _this.currentObservable.query.updateQuery(mapFn); | ||
}; | ||
_this.obsStartPolling = function (pollInterval) { | ||
return _this.currentObservable.query.startPolling(pollInterval); | ||
}; | ||
_this.obsStopPolling = function () { | ||
return _this.currentObservable.query.stopPolling(); | ||
}; | ||
_this.obsSubscribeToMore = function (options) { | ||
return _this.currentObservable.query.subscribeToMore(options); | ||
}; | ||
_this.forceUpdate = forceUpdate; | ||
@@ -123,3 +149,4 @@ return _this; | ||
skip = _a.skip, | ||
query = _a.query; | ||
query = _a.query, | ||
ssr = _a.ssr; | ||
@@ -133,3 +160,4 @@ if (skip || query !== this.previousData.query) { | ||
if (this.isMounted) this.startQuerySubscription(); | ||
return this.getExecuteSsrResult() || this.getExecuteResult(); | ||
var ssrDisabled = ssr === false; | ||
return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult(); | ||
}; | ||
@@ -147,30 +175,6 @@ | ||
QueryData.prototype.fetchData = function () { | ||
if (this.getOptions().skip) return false; | ||
var _a = this.getOptions(), | ||
children = _a.children, | ||
ssr = _a.ssr, | ||
displayName = _a.displayName, | ||
skip = _a.skip, | ||
onCompleted = _a.onCompleted, | ||
onError = _a.onError, | ||
partialRefetch = _a.partialRefetch, | ||
opts = (0, _tslib.__rest)(_a, ["children", "ssr", "displayName", "skip", "onCompleted", "onError", "partialRefetch"]); | ||
var fetchPolicy = opts.fetchPolicy; | ||
if (ssr === false) return false; | ||
if (fetchPolicy === 'network-only' || fetchPolicy === 'cache-and-network') { | ||
fetchPolicy = 'cache-first'; | ||
} | ||
var obs = this.refreshClient().client.watchQuery((0, _tslib.__assign)({}, opts, { | ||
fetchPolicy: fetchPolicy | ||
})); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(obs, this.getOptions()); | ||
} | ||
var currentResult = this.currentObservable.query.getCurrentResult(); | ||
var options = this.getOptions(); | ||
if (options.skip || options.ssr === false) return false; | ||
var obs = this.currentObservable.query; | ||
var currentResult = obs.getCurrentResult(); | ||
return currentResult.loading ? obs.result() : false; | ||
@@ -218,12 +222,17 @@ }; | ||
QueryData.prototype.getExecuteSsrResult = function () { | ||
QueryData.prototype.getExecuteSsrResult = function (ssrDisabled) { | ||
var result; | ||
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) { | ||
return ssrLoading; | ||
} | ||
result = this.context.renderPromises.addQueryPromise(this, this.getExecuteResult); | ||
@@ -240,7 +249,13 @@ | ||
QueryData.prototype.prepareObservableQueryOptions = function () { | ||
this.verifyDocumentType(this.getOptions().query, _reactCommon.DocumentType.Query); | ||
var displayName = this.getOptions().displayName || 'Query'; | ||
return (0, _tslib.__assign)({}, this.getOptions(), { | ||
var options = this.getOptions(); | ||
this.verifyDocumentType(options.query, _reactCommon.DocumentType.Query); | ||
var displayName = options.displayName || 'Query'; | ||
if (this.context && this.context.renderPromises && (options.fetchPolicy === 'network-only' || options.fetchPolicy === 'cache-and-network')) { | ||
options.fetchPolicy = 'cache-first'; | ||
} | ||
return (0, _tslib.__assign)({}, options, { | ||
displayName: displayName, | ||
context: this.getOptions().context || {}, | ||
context: options.context || {}, | ||
metadata: { | ||
@@ -254,14 +269,2 @@ reactComponent: { | ||
QueryData.prototype.observableQueryFields = function (observable) { | ||
return { | ||
variables: observable.variables, | ||
refetch: observable.refetch.bind(observable), | ||
fetchMore: observable.fetchMore.bind(observable), | ||
updateQuery: observable.updateQuery.bind(observable), | ||
startPolling: observable.startPolling.bind(observable), | ||
stopPolling: observable.stopPolling.bind(observable), | ||
subscribeToMore: observable.subscribeToMore.bind(observable) | ||
}; | ||
}; | ||
QueryData.prototype.initializeObservableQuery = function () { | ||
@@ -278,2 +281,6 @@ if (this.context && this.context.renderPromises) { | ||
this.currentObservable.query = this.refreshClient().client.watchQuery(observableQueryOptions); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(this.currentObservable.query, observableQueryOptions); | ||
} | ||
} | ||
@@ -285,2 +292,3 @@ }; | ||
this.initializeObservableQuery(); | ||
return; | ||
} | ||
@@ -308,5 +316,12 @@ | ||
data = _a.data; | ||
var previousResult = _this.previousData.result; | ||
if (_this.previousData.result && _this.previousData.result.loading === loading && _this.previousData.result.networkStatus === networkStatus && (0, _equality.equal)(_this.previousData.result.data, data)) { | ||
return; | ||
if (previousResult) { | ||
if (previousResult.loading && previousResult.networkStatus === _apolloClient.NetworkStatus.fetchMore && (0, _equality.equal)(previousResult.data, data)) { | ||
return; | ||
} | ||
if (previousResult.loading === loading && previousResult.networkStatus === networkStatus && (0, _equality.equal)(previousResult.data, data)) { | ||
return; | ||
} | ||
} | ||
@@ -343,5 +358,6 @@ | ||
QueryData.prototype.getQueryResult = function () { | ||
var result = (0, _tslib.__assign)({}, this.observableQueryFields(this.currentObservable.query)); | ||
var result = this.observableQueryFields(); | ||
var options = this.getOptions(); | ||
if (this.getOptions().skip) { | ||
if (options.skip) { | ||
result = (0, _tslib.__assign)({}, result, { | ||
@@ -384,3 +400,3 @@ data: undefined, | ||
var fetchPolicy = this.currentObservable.query.options.fetchPolicy; | ||
var partialRefetch = this.getOptions().partialRefetch; | ||
var partialRefetch = options.partialRefetch; | ||
@@ -438,2 +454,15 @@ if (partialRefetch && !data && partial && fetchPolicy !== 'cache-only') { | ||
QueryData.prototype.observableQueryFields = function () { | ||
var observable = this.currentObservable.query; | ||
return { | ||
variables: observable.variables, | ||
refetch: this.obsRefetch, | ||
fetchMore: this.obsFetchMore, | ||
updateQuery: this.obsUpdateQuery, | ||
startPolling: this.obsStartPolling, | ||
stopPolling: this.obsStopPolling, | ||
subscribeToMore: this.obsSubscribeToMore | ||
}; | ||
}; | ||
return QueryData; | ||
@@ -487,3 +516,6 @@ }(OperationData); | ||
var memo = { | ||
options: updatedOptions, | ||
options: (0, _tslib.__assign)({}, updatedOptions, { | ||
onError: undefined, | ||
onCompleted: undefined | ||
}), | ||
context: context, | ||
@@ -495,2 +527,3 @@ tick: tick | ||
}, memo); | ||
var queryResult = lazy ? result[1] : result; | ||
(0, _react.useEffect)(function () { | ||
@@ -500,3 +533,3 @@ return queryData.afterExecute({ | ||
}); | ||
}, [result]); | ||
}, [queryResult.loading, queryResult.networkStatus, queryResult.error, queryResult.data]); | ||
(0, _react.useEffect)(function () { | ||
@@ -560,2 +593,3 @@ return function () { | ||
this.verifyDocumentType(this.getOptions().mutation, _reactCommon.DocumentType.Mutation); | ||
result.client = this.refreshClient().client; | ||
return [this.runMutation, result]; | ||
@@ -729,2 +763,12 @@ }; | ||
SubscriptionData.prototype.execute = function (result) { | ||
if (this.getOptions().skip === true) { | ||
this.cleanup(); | ||
return { | ||
loading: false, | ||
error: undefined, | ||
data: undefined, | ||
variables: this.getOptions().variables | ||
}; | ||
} | ||
var currentResult = result; | ||
@@ -742,5 +786,4 @@ | ||
if (shouldResubscribe !== false && this.previousOptions && Object.keys(this.previousOptions).length > 0 && (this.previousOptions.subscription !== this.getOptions().subscription || !(0, _equality.equal)(this.previousOptions.variables, this.getOptions().variables))) { | ||
this.endSubscription(); | ||
delete this.currentObservable.query; | ||
if (shouldResubscribe !== false && this.previousOptions && Object.keys(this.previousOptions).length > 0 && (this.previousOptions.subscription !== this.getOptions().subscription || !(0, _equality.equal)(this.previousOptions.variables, this.getOptions().variables) || this.previousOptions.skip !== this.getOptions().skip)) { | ||
this.cleanup(); | ||
currentResult = this.getLoadingResult(); | ||
@@ -767,3 +810,3 @@ } | ||
SubscriptionData.prototype.initialize = function (options) { | ||
if (this.currentObservable.query) return; | ||
if (this.currentObservable.query || this.getOptions().skip === true) return; | ||
this.currentObservable.query = this.refreshClient().client.subscribe({ | ||
@@ -840,5 +883,10 @@ query: options.subscription, | ||
var context = (0, _react.useContext)((0, _reactCommon.getApolloContext)()); | ||
var updatedOptions = options ? (0, _tslib.__assign)({}, options, { | ||
subscription: subscription | ||
}) : { | ||
subscription: subscription | ||
}; | ||
var _a = (0, _react.useState)({ | ||
loading: true, | ||
loading: !updatedOptions.skip, | ||
error: undefined, | ||
@@ -850,7 +898,2 @@ data: undefined | ||
var updatedOptions = options ? (0, _tslib.__assign)({}, options, { | ||
subscription: subscription | ||
}) : { | ||
subscription: subscription | ||
}; | ||
var subscriptionDataRef = (0, _react.useRef)(); | ||
@@ -857,0 +900,0 @@ |
@@ -7,9 +7,9 @@ import * as tslib_1 from "tslib"; | ||
var context = useContext(getApolloContext()); | ||
var updatedOptions = options | ||
? tslib_1.__assign({}, options, { subscription: subscription }) : { subscription: subscription }; | ||
var _a = useState({ | ||
loading: true, | ||
loading: !updatedOptions.skip, | ||
error: undefined, | ||
data: undefined | ||
}), result = _a[0], setResult = _a[1]; | ||
var updatedOptions = options | ||
? tslib_1.__assign({}, options, { subscription: subscription }) : { subscription: subscription }; | ||
var subscriptionDataRef = useRef(); | ||
@@ -16,0 +16,0 @@ function getSubscriptionDataRef() { |
@@ -1,4 +0,4 @@ | ||
import { OperationVariables } from '@apollo/react-common'; | ||
import { OperationVariables, QueryResult } from '@apollo/react-common'; | ||
import { DocumentNode } from 'graphql'; | ||
import { QueryHookOptions } from '../types'; | ||
export declare function useBaseQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode, options?: QueryHookOptions<TData, TVariables>, lazy?: boolean): import("@apollo/react-common").QueryResult<TData, TVariables> | [(options?: import("../types").QueryLazyOptions<TVariables> | undefined) => void, import("@apollo/react-common").QueryResult<TData, TVariables>]; | ||
export declare function useBaseQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode, options?: QueryHookOptions<TData, TVariables>, lazy?: boolean): QueryResult<TData, TVariables> | [(options?: import("../types").QueryLazyOptions<TVariables> | undefined) => void, QueryResult<TData, TVariables>]; |
@@ -23,3 +23,3 @@ import * as tslib_1 from "tslib"; | ||
var memo = { | ||
options: updatedOptions, | ||
options: tslib_1.__assign({}, updatedOptions, { onError: undefined, onCompleted: undefined }), | ||
context: context, | ||
@@ -29,3 +29,11 @@ tick: tick | ||
var result = useDeepMemo(function () { return (lazy ? queryData.executeLazy() : queryData.execute()); }, memo); | ||
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [result]); | ||
var queryResult = lazy | ||
? result[1] | ||
: result; | ||
useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [ | ||
queryResult.loading, | ||
queryResult.networkStatus, | ||
queryResult.error, | ||
queryResult.data | ||
]); | ||
useEffect(function () { | ||
@@ -32,0 +40,0 @@ return function () { return queryData.cleanup(); }; |
{ | ||
"name": "@apollo/react-hooks", | ||
"description": "React Apollo Hooks.", | ||
"version": "3.1.0-beta.0", | ||
"version": "3.1.0", | ||
"author": "opensource@apollographql.com", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"predeploy": "npm run build", | ||
"deploy": "npm publish --tag beta", | ||
"deploy": "npm publish", | ||
"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.0-beta.0", | ||
"@apollo/react-common": "^3.1.0", | ||
"@wry/equality": "^0.1.9", | ||
@@ -61,7 +61,7 @@ "ts-invariant": "^0.4.4", | ||
"jest": "24.9.0", | ||
"rollup": "1.19.4", | ||
"rollup": "1.20.3", | ||
"tsc-watch": "2.4.0", | ||
"typescript": "3.5.3" | ||
}, | ||
"gitHead": "241ccacb9e27ab9cda90aa4a5c1f7ee29c05391b" | ||
"gitHead": "3bc12b7f5b2064acc7ec0e15ec59cd2acfa61d49" | ||
} |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
366442
3357
2
Updated@apollo/react-common@^3.1.0