Fixes #9827 Also uncovered a conflict with `@objectType('Relation')` and `@objectType('relation)` I don't want to address it in this PR so I will create a followup issue when we close this but I think there's a confusion between Relation/RelationMetadata, it's unclear what is what --------- Co-authored-by: Antoine Moreaux <moreaux.antoine@gmail.com>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { useMutation } from '@apollo/client';
|
|
|
|
import {
|
|
CreateOneRelationMetadataItemMutation,
|
|
CreateOneRelationMetadataItemMutationVariables,
|
|
} from '~/generated-metadata/graphql';
|
|
|
|
import { CREATE_ONE_RELATION_METADATA_ITEM } from '../graphql/mutations';
|
|
import {
|
|
formatRelationMetadataInput,
|
|
FormatRelationMetadataInputParams,
|
|
} from '../utils/formatRelationMetadataInput';
|
|
|
|
import { useRefreshObjectMetadataItems } from '@/object-metadata/hooks/useRefreshObjectMetadataItem';
|
|
import { useApolloMetadataClient } from './useApolloMetadataClient';
|
|
|
|
export const useCreateOneRelationMetadataItem = () => {
|
|
const apolloMetadataClient = useApolloMetadataClient();
|
|
|
|
const [mutate] = useMutation<
|
|
CreateOneRelationMetadataItemMutation,
|
|
CreateOneRelationMetadataItemMutationVariables
|
|
>(CREATE_ONE_RELATION_METADATA_ITEM, {
|
|
client: apolloMetadataClient,
|
|
});
|
|
|
|
const { refreshObjectMetadataItems } =
|
|
useRefreshObjectMetadataItems('network-only');
|
|
|
|
const createOneRelationMetadataItem = async (
|
|
input: FormatRelationMetadataInputParams,
|
|
) => {
|
|
const result = await mutate({
|
|
variables: {
|
|
input: { relationMetadata: formatRelationMetadataInput(input) },
|
|
},
|
|
});
|
|
|
|
await refreshObjectMetadataItems();
|
|
|
|
return result;
|
|
};
|
|
|
|
return {
|
|
createOneRelationMetadataItem,
|
|
};
|
|
};
|