@apollo/react-hooks
Advanced tools
Comparing version 0.1.0-beta.8 to 0.1.0-beta.9
@@ -122,6 +122,3 @@ import * as tslib_1 from "tslib"; | ||
error: function (error) { | ||
if (!_this.previousData.result || | ||
_this.previousData.result.networkStatus === NetworkStatus.refetch) { | ||
_this.resubscribeToQuery(); | ||
} | ||
_this.resubscribeToQuery(); | ||
if (!error.hasOwnProperty('graphQLErrors')) | ||
@@ -145,2 +142,3 @@ throw error; | ||
QueryData.prototype.getQueryResult = function () { | ||
var _this = this; | ||
var result = { | ||
@@ -191,2 +189,5 @@ data: Object.create(null) | ||
} | ||
setTimeout(function () { | ||
_this.currentObservable.query.resetQueryStoreErrors(); | ||
}); | ||
result.client = this.client; | ||
@@ -193,0 +194,0 @@ this.previousData.loading = |
@@ -77,2 +77,7 @@ import * as tslib_1 from "tslib"; | ||
var onSubscriptionData = this.getOptions().onSubscriptionData; | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
if (onSubscriptionData) { | ||
@@ -84,7 +89,2 @@ onSubscriptionData({ | ||
} | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
}; | ||
@@ -91,0 +91,0 @@ SubscriptionData.prototype.updateError = function (error) { |
@@ -257,5 +257,3 @@ exports.__esModule = true; | ||
error: function (error) { | ||
if (!_this.previousData.result || _this.previousData.result.networkStatus === _apolloClient.NetworkStatus.refetch) { | ||
_this.resubscribeToQuery(); | ||
} | ||
_this.resubscribeToQuery(); | ||
@@ -282,2 +280,4 @@ if (!error.hasOwnProperty('graphQLErrors')) throw error; | ||
QueryData.prototype.getQueryResult = function () { | ||
var _this = this; | ||
var result = { | ||
@@ -340,2 +340,5 @@ data: Object.create(null) | ||
setTimeout(function () { | ||
_this.currentObservable.query.resetQueryStoreErrors(); | ||
}); | ||
result.client = this.client; | ||
@@ -705,2 +708,7 @@ this.previousData.loading = this.previousData.result && this.previousData.result.loading || false; | ||
var onSubscriptionData = this.getOptions().onSubscriptionData; | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
@@ -713,8 +721,2 @@ if (onSubscriptionData) { | ||
} | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
}; | ||
@@ -721,0 +723,0 @@ |
@@ -1,1 +0,1 @@ | ||
exports.__esModule=!0,exports.getDataFromTree=function(t,e){void 0===e&&(e={});return l({tree:t,context:e,renderFunction:require("react-dom/server").renderToStaticMarkup})},exports.getMarkupFromTree=l,exports.renderToStringWithData=function(t){return l({tree:t,renderFunction:require("react-dom/server").renderToString})},exports.useApolloClient=function(){var e=r.default.useContext((0,t.getApolloContext)()).client;return(0,o.invariant)(e,1),e},exports.useMutation=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useState)({called:!1,loading:!1}),u=n[0],p=n[1],c=s?(0,e.__assign)({},s,{mutation:i}):{mutation:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new a({options:c,context:o,result:u,setResult:p}));return l.current}();return h.setOptions(c),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),h.execute(u)},exports.useQuery=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useReducer)(function(t){return t+1},0),a=(n[0],n[1]),p=s?(0,e.__assign)({},s,{query:i}):{query:i},c=(0,r.useRef)();var l=function(){c.current||(c.current=new u({options:p,context:o,forceUpdate:a}));return c.current}();return l.setOptions(p),l.context=o,(0,r.useEffect)(function(){return l.afterExecute()}),l.execute()},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],c=s?(0,e.__assign)({},s,{subscription:i}):{subscription:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new p({options:c,context:o,setResult:a}));return l.current}();return h.setOptions(c),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),h.execute(u)},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("apollo-utilities"),o=require("ts-invariant");var n=function(){function e(t,e){this.isMounted=!0,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.isEqual)(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.forceUpdate=s,o}return(0,e.__extends)(o,r),o.prototype.execute=function(){var t=this;this.refreshClient();var e=this.getOptions(),r=e.skip,s=e.query;(r||s!==this.previousData.query)&&(this.removeQuerySubscription(),this.previousData.query=s),this.updateObservableQuery(),r||this.startQuerySubscription();var o=function(){return t.getQueryResult()};return this.context&&this.context.renderPromises?this.context.renderPromises.addQueryPromise(this,o)||{loading:!0,networkStatus:i.NetworkStatus.loading}:o()},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(){return this.isMounted=!0,this.handleErrorOrCompleted(),this.unmount.bind(this)},o.prototype.cleanup=function(){this.removeQuerySubscription(),this.currentObservable.query=null,this.previousData.result=null},o.prototype.updateCurrentData=function(){this.isMounted&&this.forceUpdate()},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.isEqual)(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){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.isEqual)(t.previousData.result.data,o||{})||t.updateCurrentData()},error:function(e){if(t.previousData.result&&t.previousData.result.networkStatus!==i.NetworkStatus.refetch||t.resubscribeToQuery(),!e.hasOwnProperty("graphQLErrors"))throw e;t.updateCurrentData()}})}},o.prototype.resubscribeToQuery=function(){this.removeQuerySubscription();var t=this.currentObservable.query.getLastError(),e=this.currentObservable.query.getLastResult();this.currentObservable.query.resetLastResults(),this.startQuerySubscription(),Object.assign(this.currentObservable.query,{lastError:t,lastResult:e})},o.prototype.getQueryResult=function(){var t={data:Object.create(null)};if(Object.assign(t,this.observableQueryFields(this.currentObservable.query)),this.getOptions().skip)t=(0,e.__assign)({},t,{data:void 0,error:void 0,loading:!1});else{var r=this.currentObservable.query.getCurrentResult(),s=r.loading,o=r.partial,n=r.networkStatus,u=r.errors,a=r.error,p=r.data;if(p=p||Object.create(null),u&&u.length>0&&(a=new i.ApolloError({graphQLErrors:u})),Object.assign(t,{loading:s,networkStatus:n,error:a}),s){var c=this.previousData.result?this.previousData.result.data:{};Object.assign(t.data,c,p)}else if(a)Object.assign(t,{data:(this.currentObservable.query.getLastResult()||{}).data});else{var l=this.currentObservable.query.options.fetchPolicy;if(this.getOptions().partialRefetch&&0===Object.keys(p).length&&o&&"cache-only"!==l)return Object.assign(t,{loading:!0,networkStatus:i.NetworkStatus.loading}),t.refetch(),t;Object.assign(t.data,p)}}return t.client=this.client,this.previousData.loading=this.previousData.result&&this.previousData.result.loading||!1,this.previousData.result=t,t},o.prototype.handleErrorOrCompleted=function(){var t=this.currentObservable.query.getCurrentResult(),e=t.data,r=t.loading,i=t.error;if(!r){var o=this.getOptions(),n=o.query,u=o.variables,a=o.onCompleted,p=o.onError;if(this.previousOptions&&!this.previousData.loading&&(0,s.isEqual)(this.previousOptions.query,n)&&(0,s.isEqual)(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);var a=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.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){var r=this;this.verifyDocumentType(this.getOptions().mutation,t.DocumentType.Mutation);return[function(t){return r.runMutation(t)},e]},o.prototype.afterExecute=function(){return this.isMounted=!0,this.unmount.bind(this)},o.prototype.cleanup=function(){},o.prototype.runMutation=function(t){var e=this;void 0===t&&(t={}),this.onMutationStart();var r=this.generateNewMutationId();return this.mutate(t).then(function(t){return e.onMutationCompleted(t,r),t}).catch(function(t){if(e.onMutationError(t,r),!e.getOptions().onError)throw t})},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.isEqual)(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){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.isEqual)(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(){return this.isMounted=!0,this.unmount.bind(this)},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;e&&e({client:this.refreshClient().client,subscriptionData:t}),this.updateResult({data:t.data,loading:!1,error:void 0})},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 c=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}();function l(i){var s=i.tree,o=i.context,n=void 0===o?{}:o,u=i.renderFunction,a=void 0===u?require("react-dom/server").renderToStaticMarkup:u,p=new c;return Promise.resolve().then(function i(){var o=(0,t.getApolloContext)(),u=a(r.default.createElement(o.Provider,{value:(0,e.__assign)({},n,{renderPromises:p})},s));return p.hasPromises()?p.consumeAndAwaitPromises().then(i):u})} | ||
exports.__esModule=!0,exports.getDataFromTree=function(t,e){void 0===e&&(e={});return l({tree:t,context:e,renderFunction:require("react-dom/server").renderToStaticMarkup})},exports.getMarkupFromTree=l,exports.renderToStringWithData=function(t){return l({tree:t,renderFunction:require("react-dom/server").renderToString})},exports.useApolloClient=function(){var e=r.default.useContext((0,t.getApolloContext)()).client;return(0,o.invariant)(e,1),e},exports.useMutation=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useState)({called:!1,loading:!1}),u=n[0],p=n[1],c=s?(0,e.__assign)({},s,{mutation:i}):{mutation:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new a({options:c,context:o,result:u,setResult:p}));return l.current}();return h.setOptions(c),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),h.execute(u)},exports.useQuery=function(i,s){var o=(0,r.useContext)((0,t.getApolloContext)()),n=(0,r.useReducer)(function(t){return t+1},0),a=(n[0],n[1]),p=s?(0,e.__assign)({},s,{query:i}):{query:i},c=(0,r.useRef)();var l=function(){c.current||(c.current=new u({options:p,context:o,forceUpdate:a}));return c.current}();return l.setOptions(p),l.context=o,(0,r.useEffect)(function(){return l.afterExecute()}),l.execute()},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],c=s?(0,e.__assign)({},s,{subscription:i}):{subscription:i},l=(0,r.useRef)();var h=function(){l.current||(l.current=new p({options:c,context:o,setResult:a}));return l.current}();return h.setOptions(c),h.context=o,(0,r.useEffect)(function(){return h.afterExecute()}),h.execute(u)},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("apollo-utilities"),o=require("ts-invariant");var n=function(){function e(t,e){this.isMounted=!0,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.isEqual)(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.forceUpdate=s,o}return(0,e.__extends)(o,r),o.prototype.execute=function(){var t=this;this.refreshClient();var e=this.getOptions(),r=e.skip,s=e.query;(r||s!==this.previousData.query)&&(this.removeQuerySubscription(),this.previousData.query=s),this.updateObservableQuery(),r||this.startQuerySubscription();var o=function(){return t.getQueryResult()};return this.context&&this.context.renderPromises?this.context.renderPromises.addQueryPromise(this,o)||{loading:!0,networkStatus:i.NetworkStatus.loading}:o()},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(){return this.isMounted=!0,this.handleErrorOrCompleted(),this.unmount.bind(this)},o.prototype.cleanup=function(){this.removeQuerySubscription(),this.currentObservable.query=null,this.previousData.result=null},o.prototype.updateCurrentData=function(){this.isMounted&&this.forceUpdate()},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.isEqual)(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){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.isEqual)(t.previousData.result.data,o||{})||t.updateCurrentData()},error:function(e){if(t.resubscribeToQuery(),!e.hasOwnProperty("graphQLErrors"))throw e;t.updateCurrentData()}})}},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,r={data:Object.create(null)};if(Object.assign(r,this.observableQueryFields(this.currentObservable.query)),this.getOptions().skip)r=(0,e.__assign)({},r,{data:void 0,error:void 0,loading:!1});else{var s=this.currentObservable.query.getCurrentResult(),o=s.loading,n=s.partial,u=s.networkStatus,a=s.errors,p=s.error,c=s.data;if(c=c||Object.create(null),a&&a.length>0&&(p=new i.ApolloError({graphQLErrors:a})),Object.assign(r,{loading:o,networkStatus:u,error:p}),o){var l=this.previousData.result?this.previousData.result.data:{};Object.assign(r.data,l,c)}else if(p)Object.assign(r,{data:(this.currentObservable.query.getLastResult()||{}).data});else{var h=this.currentObservable.query.options.fetchPolicy;if(this.getOptions().partialRefetch&&0===Object.keys(c).length&&n&&"cache-only"!==h)return Object.assign(r,{loading:!0,networkStatus:i.NetworkStatus.loading}),r.refetch(),r;Object.assign(r.data,c)}}return setTimeout(function(){t.currentObservable.query.resetQueryStoreErrors()}),r.client=this.client,this.previousData.loading=this.previousData.result&&this.previousData.result.loading||!1,this.previousData.result=r,r},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.isEqual)(this.previousOptions.query,n)&&(0,s.isEqual)(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);var a=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.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){var r=this;this.verifyDocumentType(this.getOptions().mutation,t.DocumentType.Mutation);return[function(t){return r.runMutation(t)},e]},o.prototype.afterExecute=function(){return this.isMounted=!0,this.unmount.bind(this)},o.prototype.cleanup=function(){},o.prototype.runMutation=function(t){var e=this;void 0===t&&(t={}),this.onMutationStart();var r=this.generateNewMutationId();return this.mutate(t).then(function(t){return e.onMutationCompleted(t,r),t}).catch(function(t){if(e.onMutationError(t,r),!e.getOptions().onError)throw t})},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.isEqual)(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){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.isEqual)(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(){return this.isMounted=!0,this.unmount.bind(this)},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 c=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}();function l(i){var s=i.tree,o=i.context,n=void 0===o?{}:o,u=i.renderFunction,a=void 0===u?require("react-dom/server").renderToStaticMarkup:u,p=new c;return Promise.resolve().then(function i(){var o=(0,t.getApolloContext)(),u=a(r.default.createElement(o.Provider,{value:(0,e.__assign)({},n,{renderPromises:p})},s));return p.hasPromises()?p.consumeAndAwaitPromises().then(i):u})} |
@@ -173,6 +173,3 @@ import { parser, operationName, DocumentType, getApolloContext } from '@apollo/react-common'; | ||
error: function (error) { | ||
if (!_this.previousData.result || | ||
_this.previousData.result.networkStatus === NetworkStatus.refetch) { | ||
_this.resubscribeToQuery(); | ||
} | ||
_this.resubscribeToQuery(); | ||
if (!error.hasOwnProperty('graphQLErrors')) | ||
@@ -196,2 +193,3 @@ throw error; | ||
QueryData.prototype.getQueryResult = function () { | ||
var _this = this; | ||
var result = { | ||
@@ -242,2 +240,5 @@ data: Object.create(null) | ||
} | ||
setTimeout(function () { | ||
_this.currentObservable.query.resetQueryStoreErrors(); | ||
}); | ||
result.client = this.client; | ||
@@ -501,2 +502,7 @@ this.previousData.loading = | ||
var onSubscriptionData = this.getOptions().onSubscriptionData; | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
if (onSubscriptionData) { | ||
@@ -508,7 +514,2 @@ onSubscriptionData({ | ||
} | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
}; | ||
@@ -515,0 +516,0 @@ SubscriptionData.prototype.updateError = function (error) { |
@@ -259,5 +259,3 @@ (function (global, factory) { | ||
error: function (error) { | ||
if (!_this.previousData.result || _this.previousData.result.networkStatus === _apolloClient.NetworkStatus.refetch) { | ||
_this.resubscribeToQuery(); | ||
} | ||
_this.resubscribeToQuery(); | ||
@@ -284,2 +282,4 @@ if (!error.hasOwnProperty('graphQLErrors')) throw error; | ||
QueryData.prototype.getQueryResult = function () { | ||
var _this = this; | ||
var result = { | ||
@@ -342,2 +342,5 @@ data: Object.create(null) | ||
setTimeout(function () { | ||
_this.currentObservable.query.resetQueryStoreErrors(); | ||
}); | ||
result.client = this.client; | ||
@@ -707,2 +710,7 @@ this.previousData.loading = this.previousData.result && this.previousData.result.loading || false; | ||
var onSubscriptionData = this.getOptions().onSubscriptionData; | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
@@ -715,8 +723,2 @@ if (onSubscriptionData) { | ||
} | ||
this.updateResult({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined | ||
}); | ||
}; | ||
@@ -723,0 +725,0 @@ |
{ | ||
"name": "@apollo/react-hooks", | ||
"description": "React Apollo Hooks.", | ||
"version": "0.1.0-beta.8", | ||
"version": "0.1.0-beta.9", | ||
"author": "opensource@apollographql.com", | ||
@@ -39,11 +39,11 @@ "keywords": [ | ||
"peerDependencies": { | ||
"apollo-client": "^2.6.0", | ||
"graphql": "^14.2.1", | ||
"apollo-client": "^2.6.2", | ||
"graphql": "^14.3.1", | ||
"react": "^16.8.0" | ||
}, | ||
"dependencies": { | ||
"@apollo/react-common": "^0.1.0-beta.6", | ||
"@apollo/react-common": "^0.1.0-beta.7", | ||
"apollo-utilities": "^1.3.2", | ||
"ts-invariant": "^0.4.2", | ||
"tslib": "^1.9.3" | ||
"ts-invariant": "^0.4.4", | ||
"tslib": "^1.10.0" | ||
}, | ||
@@ -62,3 +62,3 @@ "files": [ | ||
}, | ||
"gitHead": "f0ad14e4304a9b58381b292fe8ad739a0ab4534b" | ||
"gitHead": "ce33f8a5ce250518d521de39982dc49f1fe9a793" | ||
} |
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
340111
3051
Updatedts-invariant@^0.4.4
Updatedtslib@^1.10.0