Moves system-level operations (auth, billing, admin) to use the /metadata endpoint instead of /graphql. This cleans up the endpoint separation so /graphql is purely for core objects (Company, People, etc.) and /metadata handles all system operations. Part of prep work for webhook/API key core migration.
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { useMutation } from '@apollo/client';
|
|
|
|
import {
|
|
UpdateOneObjectInput,
|
|
UpdateOneObjectMetadataItemMutation,
|
|
UpdateOneObjectMetadataItemMutationVariables,
|
|
} from '~/generated-metadata/graphql';
|
|
|
|
import { UPDATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
|
|
|
|
import { useRefreshObjectMetadataItems } from '@/object-metadata/hooks/useRefreshObjectMetadataItem';
|
|
|
|
// 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
|
|
export const useUpdateOneObjectMetadataItem = () => {
|
|
const [mutate, { loading }] = useMutation<
|
|
UpdateOneObjectMetadataItemMutation,
|
|
UpdateOneObjectMetadataItemMutationVariables
|
|
>(UPDATE_ONE_OBJECT_METADATA_ITEM);
|
|
|
|
const { refreshObjectMetadataItems } =
|
|
useRefreshObjectMetadataItems('network-only');
|
|
|
|
const updateOneObjectMetadataItem = async ({
|
|
idToUpdate,
|
|
updatePayload,
|
|
}: {
|
|
idToUpdate: UpdateOneObjectInput['id'];
|
|
updatePayload: UpdateOneObjectInput['update'];
|
|
}) => {
|
|
const result = await mutate({
|
|
variables: {
|
|
idToUpdate,
|
|
updatePayload,
|
|
},
|
|
});
|
|
|
|
await refreshObjectMetadataItems();
|
|
|
|
return result;
|
|
};
|
|
|
|
return {
|
|
updateOneObjectMetadataItem,
|
|
loading,
|
|
};
|
|
};
|