Upgrade Apollo Client to v4 and refactor error handling (#18584)
## 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>
This commit is contained in:
+3
-2
@@ -11,7 +11,8 @@ import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
|
||||
import { useState } from 'react';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
import { useUserLookupAdminPanelMutation } from '~/generated-metadata/graphql';
|
||||
import { useMutation } from '@apollo/client/react';
|
||||
import { UserLookupAdminPanelDocument } from '~/generated-metadata/graphql';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
||||
@@ -52,7 +53,7 @@ export const SettingsAdminGeneral = () => {
|
||||
);
|
||||
const [isUserLookupLoading, setIsUserLookupLoading] = useState(false);
|
||||
|
||||
const [userLookup] = useUserLookupAdminPanelMutation();
|
||||
const [userLookup] = useMutation(UserLookupAdminPanelDocument);
|
||||
|
||||
const currentUser = useAtomStateValue(currentUserState);
|
||||
|
||||
|
||||
+3
-2
@@ -2,10 +2,11 @@ import { SettingsAdminTableCard } from '@/settings/admin-panel/components/Settin
|
||||
import { SettingsAdminVersionDisplay } from '@/settings/admin-panel/components/SettingsAdminVersionDisplay';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { IconCircleDot, IconStatusChange } from 'twenty-ui/display';
|
||||
import { useGetVersionInfoQuery } from '~/generated-metadata/graphql';
|
||||
import { useQuery } from '@apollo/client/react';
|
||||
import { GetVersionInfoDocument } from '~/generated-metadata/graphql';
|
||||
|
||||
export const SettingsAdminVersionContainer = () => {
|
||||
const { data, loading } = useGetVersionInfoQuery();
|
||||
const { data, loading } = useQuery(GetVersionInfoDocument);
|
||||
const { currentVersion, latestVersion } = data?.versionInfo ?? {};
|
||||
|
||||
const versionItems = [
|
||||
|
||||
+5
-4
@@ -35,10 +35,11 @@ import { Button, Toggle } from 'twenty-ui/input';
|
||||
import { Section } from 'twenty-ui/layout';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
import { useMutation } from '@apollo/client/react';
|
||||
import {
|
||||
type FeatureFlagKey,
|
||||
useImpersonateMutation,
|
||||
useUpdateWorkspaceFeatureFlagMutation,
|
||||
ImpersonateDocument,
|
||||
UpdateWorkspaceFeatureFlagDocument,
|
||||
} from '~/generated-metadata/graphql';
|
||||
|
||||
type SettingsAdminWorkspaceContentProps = {
|
||||
@@ -64,11 +65,11 @@ export const SettingsAdminWorkspaceContent = ({
|
||||
const [currentUser] = useAtomState(currentUserState);
|
||||
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
|
||||
|
||||
const [updateFeatureFlag] = useUpdateWorkspaceFeatureFlagMutation();
|
||||
const [updateFeatureFlag] = useMutation(UpdateWorkspaceFeatureFlagDocument);
|
||||
const [isImpersonateLoading, setIsImpersonationLoading] = useState(false);
|
||||
const { executeImpersonationAuth } = useImpersonationAuth();
|
||||
const { executeImpersonationRedirect } = useImpersonationRedirect();
|
||||
const [impersonate] = useImpersonateMutation();
|
||||
const [impersonate] = useMutation(ImpersonateDocument);
|
||||
|
||||
const { updateFeatureFlagState } = useFeatureFlagState();
|
||||
const userLookupResult = useAtomStateValue(userLookupResultState);
|
||||
|
||||
Reference in New Issue
Block a user