const DELETE_DATA_TYPE = gql`
mutation DeleteDataType($id: ID!) {
deleteDataType(id: $id) {
deletedID
}
}
`;
// Using the mutation
const [deleteDataType] = useMutation(DELETE_DATA_TYPE);
const handleDeleteDataType = async (dataTypeId) => {
try {
// Check for dependencies first
const entitiesUsingDataType = await checkDataTypeUsage(dataTypeId);
if (entitiesUsingDataType.length > 0) {
console.warn('Data type is in use by:', entitiesUsingDataType);
return; // Don't delete if in use
}
const { data } = await deleteDataType({
variables: { id: dataTypeId }
});
console.log('Data type deleted:', data.deleteDataType.deletedID);
// Update UI to remove the deleted data type
} catch (error) {
console.error('Error deleting data type:', error);
}
};
# Move entities to a different data type before deletion
mutation {
updateCustomer(id: "cust_123", input: {
dataTypeSlug: "standard_customer"
clearDataTypeID: true
}) {
id dataTypeSlug
}
}
# Clear the data type reference but keep the data
mutation {
updateSupplier(id: "supp_456", input: {
clearDataTypeID: true
clearDataTypeSlug: true
# data remains intact without schema validation
}) {
id data
}
}