mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 21:47:38 +00:00
## Summary This PR upgrades Apollo Client from v3.10.0 to v4 and refactors error handling patterns across the codebase to use a new centralized `useSnackBarOnQueryError` hook. ## Key Changes - **Dependency Update**: Upgraded `@apollo/client` from `^3.10.0` to `^3.11.0` in root package.json - **New Hook**: Added `useSnackBarOnQueryError` hook for centralized Apollo query error handling with snack bar notifications - **Error Handling Refactor**: Updated 100+ files to use the new error handling pattern: - Removed direct `ApolloError` imports where no longer needed - Replaced manual error handling logic with `useSnackBarOnQueryError` hook - Simplified error handling in hooks and components across multiple modules - **GraphQL Codegen**: Updated codegen configuration files to work with Apollo Client v3.11.0 - **Type Definitions**: Added TypeScript declaration file for `apollo-upload-client` module - **Test Updates**: Updated test files to reflect new error handling patterns ## Notable Implementation Details - The new `useSnackBarOnQueryError` hook provides a consistent way to handle Apollo query errors with automatic snack bar notifications - Changes span across multiple feature areas: auth, object records, settings, workflows, billing, and more - All changes maintain backward compatibility while improving code maintainability and reducing duplication - Jest configuration updated to work with the new Apollo Client version https://claude.ai/code/session_019WGZ6Rd7sEHuBg9sTrXRqJ --------- Co-authored-by: Claude <noreply@anthropic.com>
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { useGetOneLogicFunction } from '@/logic-functions/hooks/useGetOneLogicFunction';
|
|
import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { type LogicFunction } from '~/generated-metadata/graphql';
|
|
import { useGetLogicFunctionSourceCode } from '@/logic-functions/hooks/useGetLogicFunctionSourceCode';
|
|
import { DEFAULT_TOOL_INPUT_SCHEMA } from 'twenty-shared/logic-function';
|
|
|
|
export type LogicFunctionFormValues = {
|
|
name: string;
|
|
description: string;
|
|
isTool: boolean;
|
|
timeoutSeconds: number;
|
|
sourceHandlerCode: string;
|
|
toolInputSchema?: object;
|
|
};
|
|
|
|
type SetLogicFunctionFormValues = Dispatch<
|
|
SetStateAction<LogicFunctionFormValues>
|
|
>;
|
|
|
|
export const useLogicFunctionUpdateFormState = ({
|
|
logicFunctionId,
|
|
}: {
|
|
logicFunctionId: string;
|
|
}): {
|
|
formValues: LogicFunctionFormValues;
|
|
logicFunction: LogicFunction | null;
|
|
setFormValues: SetLogicFunctionFormValues;
|
|
loading: boolean;
|
|
} => {
|
|
const [formValues, setFormValues] = useState<LogicFunctionFormValues>({
|
|
name: '',
|
|
description: '',
|
|
isTool: false,
|
|
sourceHandlerCode: '',
|
|
timeoutSeconds: 300,
|
|
toolInputSchema: DEFAULT_TOOL_INPUT_SCHEMA,
|
|
});
|
|
|
|
const { sourceHandlerCode, loading: logicFunctionSourceCodeLoading } =
|
|
useGetLogicFunctionSourceCode({
|
|
logicFunctionId,
|
|
});
|
|
|
|
const { logicFunction, loading: logicFunctionLoading } =
|
|
useGetOneLogicFunction({
|
|
id: logicFunctionId,
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (isDefined(logicFunction)) {
|
|
setFormValues((prevState) => ({
|
|
...prevState,
|
|
name: logicFunction.name || '',
|
|
description: logicFunction.description || '',
|
|
isTool: logicFunction.isTool ?? false,
|
|
timeoutSeconds: logicFunction.timeoutSeconds ?? 300,
|
|
toolInputSchema:
|
|
logicFunction.toolInputSchema || DEFAULT_TOOL_INPUT_SCHEMA,
|
|
}));
|
|
}
|
|
}, [logicFunction]);
|
|
|
|
useEffect(() => {
|
|
if (isDefined(sourceHandlerCode)) {
|
|
setFormValues((prev) => ({
|
|
...prev,
|
|
sourceHandlerCode,
|
|
}));
|
|
}
|
|
}, [sourceHandlerCode]);
|
|
|
|
return {
|
|
formValues,
|
|
setFormValues,
|
|
logicFunction,
|
|
loading: logicFunctionLoading || logicFunctionSourceCodeLoading,
|
|
};
|
|
};
|