**Context** When creating a new object, it creates the "All ...." view associated. After new object is created, in `PrefetchRunViewQueryEffect`, findManyViews returns cached results WITHOUT the new view. git bisect - regression introduced with https://github.com/twentyhq/twenty/pull/10272 **Attempt** : Update to 'network-only' fetch policy in `PrefetchRunViewQueryEffect` -> not working on useQuery apollo hook (🤯) : query is handle by cache and not network **Solution** Based on pattern used for view creation (`useCreateViewFromCurrentView`), refreshing the view cache with a `useLazyFindManyRecords` solves the issue. Then, `prefetchViewsState` is updated in `PrefetchRunViewQueryEffect` closes : https://github.com/twentyhq/core-team-issues/issues/845
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useMutation } from '@apollo/client';
|
|
|
|
import {
|
|
CreateObjectInput,
|
|
CreateOneObjectMetadataItemMutation,
|
|
CreateOneObjectMetadataItemMutationVariables,
|
|
} from '~/generated-metadata/graphql';
|
|
|
|
import { CREATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
|
|
|
|
import { useRefreshObjectMetadataItems } from '@/object-metadata/hooks/useRefreshObjectMetadataItem';
|
|
import { useRefreshCachedViews } from '@/views/hooks/useRefreshViews';
|
|
import { useApolloMetadataClient } from './useApolloMetadataClient';
|
|
|
|
export const useCreateOneObjectMetadataItem = () => {
|
|
const { refreshCachedViews } = useRefreshCachedViews();
|
|
|
|
const apolloMetadataClient = useApolloMetadataClient();
|
|
const { refreshObjectMetadataItems } =
|
|
useRefreshObjectMetadataItems('network-only');
|
|
|
|
const [mutate] = useMutation<
|
|
CreateOneObjectMetadataItemMutation,
|
|
CreateOneObjectMetadataItemMutationVariables
|
|
>(CREATE_ONE_OBJECT_METADATA_ITEM, {
|
|
client: apolloMetadataClient,
|
|
});
|
|
|
|
const createOneObjectMetadataItem = async (input: CreateObjectInput) => {
|
|
const createdObjectMetadata = await mutate({
|
|
variables: {
|
|
input: { object: input },
|
|
},
|
|
});
|
|
|
|
await refreshObjectMetadataItems();
|
|
refreshCachedViews();
|
|
return createdObjectMetadata;
|
|
};
|
|
|
|
return {
|
|
createOneObjectMetadataItem,
|
|
};
|
|
};
|