console: fixed false positives in redux syncing metadata to react-query

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9713
GitOrigin-RevId: 2fe9f196282a55511f40f8d64e63d889f73381d8
This commit is contained in:
Matthew Goodwin 2023-06-30 10:48:26 -05:00 committed by hasura-bot
parent fd5b61cda6
commit 37dd302729
3 changed files with 33 additions and 14 deletions

View File

@ -8,8 +8,7 @@ import { isEmpty } from './components/Common/utils/jsUtils';
import { stripTrailingSlash } from './components/Common/utils/urlUtils';
import { SERVER_CONSOLE_MODE } from './constants';
import { parseConsoleType, ConsoleType } from './utils/envUtils';
import { QueryClient } from 'react-query';
import { ConsoleType, parseConsoleType } from './utils/envUtils';
export type LuxFeature =
| 'DatadogIntegration'
@ -180,7 +179,6 @@ export type EnvVars = {
declare global {
interface Window extends GlobalWindowHeap {
__env: EnvVars;
reactQueryClient: QueryClient;
}
const CONSOLE_ASSET_VERSION: string;
}

View File

@ -4,12 +4,6 @@ import { ReactQueryDevtools } from 'react-query/devtools';
export const reactQueryClient = new QueryClient();
/**
* This is needed by the redux store to trigger
* invalidate queries when the metadata is updated in the store.
*/
window.reactQueryClient = reactQueryClient;
export const ReactQueryProvider: React.FC = ({ children }) => (
<QueryClientProvider client={reactQueryClient}>
{children}

View File

@ -1,20 +1,47 @@
import { ToolkitStore } from '@reduxjs/toolkit/dist/configureStore';
import { reactQueryClient } from './lib/reactQuery';
import { Metadata } from './features/hasura-metadata-types';
import { METADATA_QUERY_KEY } from './features/hasura-metadata-api/useMetadata';
let previousStore: any = null;
export const listenForStoreMetadataChanges = (store: ToolkitStore) => {
let previousStore: any = null;
store.subscribe(() => {
if (!previousStore) {
if (!previousStore || previousStore?.metadata?.metadataObject == null) {
previousStore = store.getState();
return;
}
const currentStore = store.getState();
const reactQueryResourceVersion =
reactQueryClient.getQueryData<Metadata>(
METADATA_QUERY_KEY
)?.resource_version;
if (
currentStore?.metadata?.resourceVersion >
previousStore?.metadata?.resourceVersion
previousStore?.metadata?.resourceVersion &&
currentStore?.metadata?.resourceVersion !== reactQueryResourceVersion
) {
window.reactQueryClient.invalidateQueries('export_metadata');
console.groupCollapsed(
'Metadata change occurred in redux, and is no longer in sync with react-query:'
);
console.info(
`current redux store rv: ${currentStore?.metadata?.resourceVersion}`
);
console.info(
`previous redux store rv: ${previousStore?.metadata?.resourceVersion}`
);
console.info(`react query rv: ${reactQueryResourceVersion}`);
console.info(
`Triggering react-query invalidation of query key: ${METADATA_QUERY_KEY}`
);
console.groupEnd();
reactQueryClient.invalidateQueries(METADATA_QUERY_KEY);
}
previousStore = store.getState();
previousStore = currentStore;
});
};