From 4f57d506ebcbd3986402866668e19177bead78ee Mon Sep 17 00:00:00 2001 From: James Wyatt Cready-Pyle Date: Thu, 21 Mar 2019 11:34:11 -0400 Subject: [PATCH] Provide shouldInvalidatePreviousData prop Fixes #2202 --- src/Query.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Query.tsx b/src/Query.tsx index 6379f868d9..43878ce93c 100644 --- a/src/Query.tsx +++ b/src/Query.tsx @@ -94,6 +94,7 @@ export default class Query extends static propTypes = { client: PropTypes.object, children: PropTypes.func.isRequired, + shouldInvalidatePreviousData: PropTypes.func, fetchPolicy: PropTypes.string, notifyOnNetworkStatusChange: PropTypes.bool, onCompleted: PropTypes.func, @@ -202,6 +203,10 @@ export default class Query extends this.queryObservable = null; this.previousData = {}; this.updateQuery(nextProps); + } else if (typeof nextProps.shouldInvalidatePreviousData === 'function') { + if (nextProps.shouldInvalidatePreviousData(nextProps.variables, this.props.variables)) { + this.previousData = {}; + } } if (this.props.query !== nextProps.query) {