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
-1
@@ -3,7 +3,9 @@ import { type Reference } from '@apollo/client';
|
||||
import { encodeCursor } from '@/apollo/utils/encodeCursor';
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { type RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { type ToReferenceFunction } from '@apollo/client/cache/core/types/common';
|
||||
import { type FieldFunctionOptions } from '@apollo/client/cache';
|
||||
|
||||
type ToReferenceFunction = FieldFunctionOptions['toReference'];
|
||||
|
||||
import { createCacheEdgeWithRecordRef } from '@/object-record/cache/utils/createCacheEdgeWithRecordRef';
|
||||
|
||||
|
||||
Vendored
+3
-1
@@ -3,7 +3,9 @@ import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataI
|
||||
import { type RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';
|
||||
import { getEdgeTypename } from '@/object-record/cache/utils/getEdgeTypename';
|
||||
import { type RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { type ToReferenceFunction } from '@apollo/client/cache/core/types/common';
|
||||
import { type FieldFunctionOptions } from '@apollo/client/cache';
|
||||
|
||||
type ToReferenceFunction = FieldFunctionOptions['toReference'];
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
type CreateCacheEdgeWithRecordRefParams = {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ export const deleteRecordFromCache = ({
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
recordToDestroy: ObjectRecord;
|
||||
cache: ApolloCache<object>;
|
||||
cache: ApolloCache;
|
||||
objectPermissionsByObjectMetadataId: Record<
|
||||
string,
|
||||
ObjectPermissions & { objectMetadataId: string }
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { type RecordGqlFields } from '@/object-record/graphql/record-gql-fields/types/RecordGqlFields';
|
||||
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isNonEmptyArray } from '@apollo/client/utilities';
|
||||
import { isObject } from '@sniptt/guards';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
|
||||
export const filterRecordOnGqlFields = ({
|
||||
record,
|
||||
recordGqlFields,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import { capitalize, isEmptyObject } from 'twenty-shared/utils';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
|
||||
export type GetRecordFromCacheArgs = {
|
||||
cache: ApolloCache<unknown>;
|
||||
cache: ApolloCache;
|
||||
recordId: string;
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
objectMetadataItem: Pick<
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export const modifyRecordFromCache = <
|
||||
recordId,
|
||||
}: {
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
cache: ApolloCache<object>;
|
||||
cache: ApolloCache;
|
||||
fieldModifiers: Modifiers<CachedObjectRecord>;
|
||||
recordId: string;
|
||||
}) => {
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ export const updateRecordFromCache = <T extends ObjectRecord>({
|
||||
}: {
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
cache: ApolloCache<object>;
|
||||
cache: ApolloCache;
|
||||
recordGqlFields: RecordGqlFields;
|
||||
record: T;
|
||||
objectPermissionsByObjectMetadataId: Record<
|
||||
|
||||
Reference in New Issue
Block a user