Move settings data model refreshMetadata to sync calls (#9046)

In this PR, I'm
- removing setting up the isAppWaitingForFreshMetadata boolean state in
PageChangeEffect navigate (not robust) to some precise synchronous
places, improving the control we have on when the app considers it's
ready to be rendered based on fresh metadata
- fixing tests
This commit is contained in:
Charles Bochet
2024-12-13 13:14:10 +01:00
committed by GitHub
parent b10d831371
commit 9579f22bc2
19 changed files with 204 additions and 79 deletions

View File

@ -1,5 +1,4 @@
import { useMutation } from '@apollo/client';
import { getOperationName } from '@apollo/client/utilities';
import {
UpdateOneObjectInput,
@ -8,8 +7,8 @@ import {
} from '~/generated-metadata/graphql';
import { UPDATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useRefreshObjectMetadataItems } from '@/object-metadata/hooks/useRefreshObjectMetadataItem';
import { useApolloMetadataClient } from './useApolloMetadataClient';
// TODO: Slice the Apollo store synchronously in the update function instead of subscribing, so we can use update after read in the same function call
@ -23,6 +22,9 @@ export const useUpdateOneObjectMetadataItem = () => {
client: apolloClientMetadata ?? undefined,
});
const { refreshObjectMetadataItems } =
useRefreshObjectMetadataItems('network-only');
const updateOneObjectMetadataItem = async ({
idToUpdate,
updatePayload,
@ -30,14 +32,16 @@ export const useUpdateOneObjectMetadataItem = () => {
idToUpdate: UpdateOneObjectInput['id'];
updatePayload: UpdateOneObjectInput['update'];
}) => {
return await mutate({
const result = await mutate({
variables: {
idToUpdate,
updatePayload,
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
await refreshObjectMetadataItems();
return result;
};
return {