Separate system operations from core objects in GraphQL endpoints (#12977)

Moves system-level operations (auth, billing, admin) to use the
/metadata endpoint instead of /graphql.

This cleans up the endpoint separation so /graphql is purely for core
objects (Company, People, etc.) and /metadata handles all system
operations.

Part of prep work for webhook/API key core migration.
This commit is contained in:
nitin
2025-07-01 21:59:32 +05:30
committed by GitHub
parent 76c517aa29
commit d2ddd6f473
229 changed files with 9425 additions and 8804 deletions
@@ -5,7 +5,8 @@ import { useAggregateRecordsQuery } from '@/object-record/hooks/useAggregateReco
import { AggregateOperations } from '@/object-record/record-table/constants/AggregateOperations';
import { generateAggregateQuery } from '@/object-record/utils/generateAggregateQuery';
import { renderHook } from '@testing-library/react';
import { FieldMetadataType } from '~/generated/graphql';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper';
jest.mock('@/object-metadata/hooks/useObjectMetadataItem');
jest.mock('@/object-record/utils/generateAggregateQuery');
@@ -50,6 +51,10 @@ const mockObjectMetadataItem: ObjectMetadataItem = {
isSystem: false,
};
const Wrapper = getJestMetadataAndApolloMocksWrapper({
apolloMocks: [],
});
describe('useAggregateRecordsQuery', () => {
beforeEach(() => {
jest.clearAllMocks();
@@ -67,13 +72,15 @@ describe('useAggregateRecordsQuery', () => {
});
it('should handle simple count operation', () => {
const { result } = renderHook(() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
name: [AggregateOperations.COUNT],
},
}),
const { result } = renderHook(
() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
name: [AggregateOperations.COUNT],
},
}),
{ wrapper: Wrapper },
);
expect(result.current.gqlFieldToFieldMap).toEqual({
@@ -88,13 +95,15 @@ describe('useAggregateRecordsQuery', () => {
});
it('should handle field aggregation', () => {
const { result } = renderHook(() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
amount: [AggregateOperations.SUM],
},
}),
const { result } = renderHook(
() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
amount: [AggregateOperations.SUM],
},
}),
{ wrapper: Wrapper },
);
expect(result.current.gqlFieldToFieldMap).toEqual({
@@ -111,26 +120,30 @@ describe('useAggregateRecordsQuery', () => {
it('should throw error for invalid aggregation operation', () => {
expect(() =>
renderHook(() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
name: [AggregateOperations.SUM],
},
}),
renderHook(
() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
name: [AggregateOperations.SUM],
},
}),
{ wrapper: Wrapper },
),
).toThrow();
});
it('should handle multiple aggregations', () => {
const { result } = renderHook(() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
amount: [AggregateOperations.SUM],
name: [AggregateOperations.COUNT],
},
}),
const { result } = renderHook(
() =>
useAggregateRecordsQuery({
objectNameSingular: 'company',
recordGqlFieldsAggregate: {
amount: [AggregateOperations.SUM],
name: [AggregateOperations.COUNT],
},
}),
{ wrapper: Wrapper },
);
expect(result.current.gqlFieldToFieldMap).toHaveProperty('sumAmount');
@@ -1,10 +1,10 @@
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useRefetchAggregateQueries } from '@/object-record/hooks/useRefetchAggregateQueries';
import { getAggregateQueryName } from '@/object-record/utils/getAggregateQueryName';
import { useApolloClient } from '@apollo/client';
import { renderHook } from '@testing-library/react';
jest.mock('@apollo/client', () => ({
useApolloClient: jest.fn(),
jest.mock('@/object-metadata/hooks/useApolloCoreClient', () => ({
useApolloCoreClient: jest.fn(),
}));
describe('useRefetchAggregateQueries', () => {
@@ -15,7 +15,7 @@ describe('useRefetchAggregateQueries', () => {
beforeEach(() => {
jest.clearAllMocks();
(useApolloClient as jest.Mock).mockReturnValue(mockApolloClient);
(useApolloCoreClient as jest.Mock).mockReturnValue(mockApolloClient);
});
it('should refetch queries', async () => {
@@ -1,5 +1,6 @@
import { useQuery } from '@apollo/client';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordGqlFieldsAggregate } from '@/object-record/graphql/types/RecordGqlFieldsAggregate';
import { RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter';
@@ -31,6 +32,8 @@ export const useAggregateRecords = <T extends AggregateRecordsData>({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const { aggregateQuery, gqlFieldToFieldMap } = useAggregateRecordsQuery({
objectNameSingular,
recordGqlFieldsAggregate,
@@ -49,6 +52,7 @@ export const useAggregateRecords = <T extends AggregateRecordsData>({
variables: {
filter,
},
client: apolloCoreClient,
},
);
@@ -1,3 +1,4 @@
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordGqlFields } from '@/object-record/graphql/types/RecordGqlFields';
import { RecordGqlFieldsAggregate } from '@/object-record/graphql/types/RecordGqlFieldsAggregate';
@@ -25,6 +26,7 @@ export const useAggregateRecordsQuery = ({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const availableAggregations = useMemo(
() => getAvailableAggregationsFromObjectFields(objectMetadataItem.fields),
[objectMetadataItem.fields],
@@ -49,6 +51,9 @@ export const useAggregateRecordsQuery = ({
recordGqlFields[fieldToQuery] = true;
});
},
{
client: apolloCoreClient,
},
);
const aggregateQuery = generateAggregateQuery({
@@ -1,6 +1,5 @@
import { useApolloClient } from '@apollo/client';
import { CustomError } from '@/error-handler/CustomError';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -20,7 +19,7 @@ export const useAttachRelatedRecordFromRecord = ({
recordObjectNameSingular,
fieldNameOnRecordObject,
}: useAttachRelatedRecordFromRecordProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular: recordObjectNameSingular,
@@ -98,7 +97,7 @@ export const useAttachRelatedRecordFromRecord = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem: relatedObjectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: {
...cachedRelatedRecord,
[fieldOnRelatedObject]: previousRecord,
@@ -1,9 +1,9 @@
import { useApolloClient } from '@apollo/client';
import { v4 } from 'uuid';
import { triggerCreateRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerCreateRecordsOptimisticEffect';
import { triggerDestroyRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDestroyRecordsOptimisticEffect';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { hasObjectMetadataItemFieldCreatedBy } from '@/object-metadata/utils/hasObjectMetadataItemFieldCreatedBy';
@@ -49,7 +49,7 @@ export const useCreateManyRecords = <
shouldMatchRootQueryFilter,
shouldRefetchAggregateQueries = true,
}: useCreateManyRecordsProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -120,7 +120,7 @@ export const useCreateManyRecords = <
if (shouldDoOptimisticEffect) {
const optimisticRecordInput = {
...computeOptimisticRecordFromInput({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
objectMetadataItems,
currentWorkspaceMember: currentWorkspaceMember,
@@ -158,7 +158,7 @@ export const useCreateManyRecords = <
.filter(isDefined);
triggerCreateRecordsOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
recordsToCreate: recordNodeCreatedInCache,
objectMetadataItems,
@@ -171,7 +171,7 @@ export const useCreateManyRecords = <
objectMetadataItem.namePlural,
);
const createdObjects = await apolloClient
const createdObjects = await apolloCoreClient
.mutate({
mutation: createManyRecordsMutation,
variables: {
@@ -204,13 +204,13 @@ export const useCreateManyRecords = <
deleteRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
recordToDestroy,
});
});
triggerDestroyRecordsOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
recordsToDestroy: recordsCreatedInCache,
objectMetadataItems,
@@ -1,10 +1,10 @@
import { useApolloClient } from '@apollo/client';
import { useState } from 'react';
import { v4 } from 'uuid';
import { triggerCreateRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerCreateRecordsOptimisticEffect';
import { triggerDestroyRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDestroyRecordsOptimisticEffect';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useCreateOneRecordInCache } from '@/object-record/cache/hooks/useCreateOneRecordInCache';
@@ -39,7 +39,7 @@ export const useCreateOneRecord = <
skipPostOptimisticEffect = false,
shouldMatchRootQueryFilter,
}: useCreateOneRecordProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const [loading, setLoading] = useState(false);
const { objectMetadataItem } = useObjectMetadataItem({
@@ -83,7 +83,7 @@ export const useCreateOneRecord = <
};
const optimisticRecordInput = computeOptimisticRecordFromInput({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
currentWorkspaceMember: currentWorkspaceMember,
objectMetadataItem,
objectMetadataItems,
@@ -111,7 +111,7 @@ export const useCreateOneRecord = <
if (skipPostOptimisticEffect === false && optimisticRecordNode !== null) {
triggerCreateRecordsOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
recordsToCreate: [optimisticRecordNode],
objectMetadataItems,
@@ -124,7 +124,7 @@ export const useCreateOneRecord = <
const mutationResponseField =
getCreateOneRecordMutationResponseField(objectNameSingular);
const createdObject = await apolloClient
const createdObject = await apolloCoreClient
.mutate({
mutation: createOneRecordMutation,
variables: {
@@ -155,12 +155,12 @@ export const useCreateOneRecord = <
deleteRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
recordToDestroy: recordCreatedInCache,
});
triggerDestroyRecordsOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
recordsToDestroy: [recordCreatedInCache],
objectMetadataItems,
@@ -1,7 +1,6 @@
import { useApolloClient } from '@apollo/client';
import { triggerUpdateRecordOptimisticEffectByBatch } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffectByBatch';
import { apiConfigState } from '@/client-config/states/apiConfigState';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -38,7 +37,7 @@ export const useDeleteManyRecords = ({
const mutationPageSize =
apiConfig?.mutationMaximumAffectedRecords ?? DEFAULT_MUTATION_BATCH_SIZE;
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -79,7 +78,9 @@ export const useDeleteManyRecords = ({
);
const cachedRecords = batchedIdsToDelete
.map((idToDelete) => getRecordFromCache(idToDelete, apolloClient.cache))
.map((idToDelete) =>
getRecordFromCache(idToDelete, apolloCoreClient.cache),
)
.filter(isDefined);
const currentTimestamp = new Date().toISOString();
if (!skipOptimisticEffect) {
@@ -113,7 +114,7 @@ export const useDeleteManyRecords = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: computedOptimisticRecord,
recordGqlFields,
objectPermissionsByObjectMetadataId,
@@ -125,7 +126,7 @@ export const useDeleteManyRecords = ({
});
triggerUpdateRecordOptimisticEffectByBatch({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecords: cachedRecordsNode,
updatedRecords: computedOptimisticRecordsNode,
@@ -133,7 +134,7 @@ export const useDeleteManyRecords = ({
});
}
const deletedRecordsResponse = await apolloClient
const deletedRecordsResponse = await apolloCoreClient
.mutate<Record<string, ObjectRecord[]>>({
mutation: deleteManyRecordsMutation,
variables: {
@@ -155,7 +156,7 @@ export const useDeleteManyRecords = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: { ...cachedRecord, deletedAt: null },
recordGqlFields,
objectPermissionsByObjectMetadataId,
@@ -195,7 +196,7 @@ export const useDeleteManyRecords = ({
});
triggerUpdateRecordOptimisticEffectByBatch({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecords: computedOptimisticRecordsNode,
updatedRecords: cachedRecordsNode,
@@ -1,7 +1,7 @@
import { useApolloClient } from '@apollo/client';
import { useCallback } from 'react';
import { triggerUpdateRecordOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffect';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -23,7 +23,7 @@ type useDeleteOneRecordProps = {
export const useDeleteOneRecord = ({
objectNameSingular,
}: useDeleteOneRecordProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -48,7 +48,10 @@ export const useDeleteOneRecord = ({
const deleteOneRecord = useCallback(
async (idToDelete: string) => {
const cachedRecord = getRecordFromCache(idToDelete, apolloClient.cache);
const cachedRecord = getRecordFromCache(
idToDelete,
apolloCoreClient.cache,
);
const cachedRecordNode = getRecordNodeFromRecord<ObjectRecord>({
record: cachedRecord,
objectMetadataItem,
@@ -82,14 +85,14 @@ export const useDeleteOneRecord = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: computedOptimisticRecord,
recordGqlFields,
objectPermissionsByObjectMetadataId,
});
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecord: cachedRecordNode,
updatedRecord: optimisticRecordNode,
@@ -97,7 +100,7 @@ export const useDeleteOneRecord = ({
});
}
const deletedRecord = await apolloClient
const deletedRecord = await apolloCoreClient
.mutate({
mutation: deleteOneRecordMutation,
variables: {
@@ -129,7 +132,7 @@ export const useDeleteOneRecord = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: {
...cachedRecord,
deletedAt: null,
@@ -139,7 +142,7 @@ export const useDeleteOneRecord = ({
});
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecord: optimisticRecordNode,
updatedRecord: cachedRecordNode,
@@ -153,7 +156,7 @@ export const useDeleteOneRecord = ({
return deletedRecord.data?.[mutationResponseField] ?? null;
},
[
apolloClient,
apolloCoreClient,
deleteOneRecordMutation,
getRecordFromCache,
mutationResponseField,
@@ -1,8 +1,7 @@
import { useApolloClient } from '@apollo/client';
import { triggerCreateRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerCreateRecordsOptimisticEffect';
import { triggerDestroyRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDestroyRecordsOptimisticEffect';
import { apiConfigState } from '@/client-config/states/apiConfigState';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -35,7 +34,7 @@ export const useDestroyManyRecords = ({
const mutationPageSize =
apiConfig?.mutationMaximumAffectedRecords ?? DEFAULT_MUTATION_BATCH_SIZE;
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -75,10 +74,10 @@ export const useDestroyManyRecords = ({
);
const cachedRecords = batchedIdToDestroy
.map((recordId) => getRecordFromCache(recordId, apolloClient.cache))
.map((recordId) => getRecordFromCache(recordId, apolloCoreClient.cache))
.filter(isDefined);
const destroyedRecordsResponse = await apolloClient
const destroyedRecordsResponse = await apolloCoreClient
.mutate<Record<string, ObjectRecord[]>>({
mutation: destroyManyRecordsMutation,
variables: {
@@ -117,7 +116,7 @@ export const useDestroyManyRecords = ({
.catch((error: Error) => {
if (cachedRecords.length > 0 && !skipOptimisticEffect) {
triggerCreateRecordsOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
recordsToCreate: cachedRecords,
objectMetadataItems,
@@ -1,8 +1,8 @@
import { useApolloClient } from '@apollo/client';
import { useCallback } from 'react';
import { triggerCreateRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerCreateRecordsOptimisticEffect';
import { triggerDestroyRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDestroyRecordsOptimisticEffect';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -19,7 +19,7 @@ type useDestroyOneRecordProps = {
export const useDestroyOneRecord = ({
objectNameSingular,
}: useDestroyOneRecordProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -40,10 +40,10 @@ export const useDestroyOneRecord = ({
async (idToDestroy: string) => {
const originalRecord = getRecordFromCache(
idToDestroy,
apolloClient.cache,
apolloCoreClient.cache,
);
const deletedRecord = await apolloClient
const deletedRecord = await apolloCoreClient
.mutate({
mutation: destroyOneRecordMutation,
variables: { idToDestroy },
@@ -70,7 +70,7 @@ export const useDestroyOneRecord = ({
.catch((error: Error) => {
if (isDefined(originalRecord)) {
triggerCreateRecordsOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
recordsToCreate: [originalRecord],
objectMetadataItems,
@@ -84,7 +84,7 @@ export const useDestroyOneRecord = ({
return deletedRecord.data?.[mutationResponseField] ?? null;
},
[
apolloClient,
apolloCoreClient,
destroyOneRecordMutation,
getRecordFromCache,
mutationResponseField,
@@ -1,5 +1,6 @@
import { Reference, useApolloClient } from '@apollo/client';
import { Reference } from '@apollo/client';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getRefName } from '@/object-record/cache/utils/getRefName';
import { modifyRecordFromCache } from '@/object-record/cache/utils/modifyRecordFromCache';
@@ -14,7 +15,7 @@ export const useDetachRelatedRecordFromRecord = ({
recordObjectNameSingular,
fieldNameOnRecordObject,
}: useDetachRelatedRecordFromRecordProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular: recordObjectNameSingular,
@@ -49,7 +50,7 @@ export const useDetachRelatedRecordFromRecord = ({
}) => {
modifyRecordFromCache({
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
fieldModifiers: {
[fieldNameOnRecordObject]: (
fieldNameOnRecordObjectConnection,
@@ -24,6 +24,7 @@ import { OnFindManyRecordsCompleted } from '@/object-record/types/OnFindManyReco
import { filterUniqueRecordEdgesByCursor } from '@/object-record/utils/filterUniqueRecordEdgesByCursor';
import { getQueryIdentifier } from '@/object-record/utils/getQueryIdentifier';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { capitalize, isDefined } from 'twenty-shared/utils';
import { cursorFamilyState } from '../states/cursorFamilyState';
import { hasNextPageFamilyState } from '../states/hasNextPageFamilyState';
@@ -76,6 +77,8 @@ export const useFetchMoreRecordsWithPagination = <
objectMetadataItem,
onCompleted,
}: UseFindManyRecordsStateParams<T>) => {
const apolloCoreClient = useApolloCoreClient();
const queryIdentifier = getQueryIdentifier({
objectNameSingular,
filter,
@@ -121,6 +124,7 @@ export const useFetchMoreRecordsWithPagination = <
lastCursor: isNonEmptyString(lastCursorLocal)
? lastCursorLocal
: undefined,
client: apolloCoreClient,
},
updateQuery: (prev, { fetchMoreResult }) => {
const previousEdges =
@@ -203,6 +207,7 @@ export const useFetchMoreRecordsWithPagination = <
onCompleted,
handleFindManyRecordsError,
queryIdentifier,
apolloCoreClient,
],
);
@@ -1,6 +1,7 @@
import { useQuery } from '@apollo/client';
import { useMemo } from 'react';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection';
@@ -25,6 +26,8 @@ export const useFindDuplicateRecords = <T extends ObjectRecord = ObjectRecord>({
}) => {
const findDuplicateQueryStateIdentifier = objectNameSingular;
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
});
@@ -47,6 +50,7 @@ export const useFindDuplicateRecords = <T extends ObjectRecord = ObjectRecord>({
variables: {
ids: objectRecordIds,
},
client: apolloCoreClient,
onCompleted: (data) => {
onCompleted?.(data[queryResponseField]);
},
@@ -1,5 +1,6 @@
import { useQuery, WatchQueryFetchPolicy } from '@apollo/client';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { RecordGqlOperationFindManyResult } from '@/object-record/graphql/types/RecordGqlOperationFindManyResult';
@@ -40,7 +41,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const { findManyRecordsQuery } = useFindManyRecordsQuery({
objectNameSingular,
recordGqlFields,
@@ -94,6 +95,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
fetchPolicy: fetchPolicy,
onCompleted: handleFindManyRecordsCompleted,
onError: handleFindManyRecordsError,
client: apolloCoreClient,
});
const { fetchMoreRecords, records, hasNextPage } =
@@ -1,6 +1,7 @@
import { useQuery } from '@apollo/client';
import { useMemo } from 'react';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
@@ -30,6 +31,8 @@ export const useFindOneRecord = <T extends ObjectRecord = ObjectRecord>({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const computedRecordGqlFields =
recordGqlFields ?? generateDepthOneRecordGqlFields({ objectMetadataItem });
@@ -50,6 +53,7 @@ export const useFindOneRecord = <T extends ObjectRecord = ObjectRecord>({
}>(findOneRecordQuery, {
skip: !objectMetadataItem || !objectRecordId || skip || !hasReadPermission,
variables: { objectRecordId },
client: apolloCoreClient,
onCompleted: (data) => {
const recordWithoutConnection = getRecordFromRecordNode<T>({
recordNode: { ...data[objectNameSingular] },
@@ -1,6 +1,7 @@
import { useLazyQuery } from '@apollo/client';
import { useRecoilCallback } from 'recoil';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection';
import { RecordGqlOperationFindManyResult } from '@/object-record/graphql/types/RecordGqlOperationFindManyResult';
@@ -31,6 +32,8 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const { findManyRecordsQuery } = useFindManyRecordsQuery({
objectNameSingular,
recordGqlFields,
@@ -68,6 +71,7 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
fetchPolicy: 'cache-first',
onCompleted: handleFindManyRecordsCompleted,
onError: handleFindManyRecordsError,
client: apolloCoreClient,
});
const { fetchMoreRecordsLazy } = useLazyFetchMoreRecordsWithPagination<T>({
@@ -1,5 +1,6 @@
import { useLazyQuery, WatchQueryFetchPolicy } from '@apollo/client';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
@@ -29,6 +30,8 @@ export const useLazyFindOneRecord = <T extends ObjectRecord = ObjectRecord>({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const { findOneRecordQuery } = useFindOneRecordQuery({
objectNameSingular,
recordGqlFields:
@@ -48,6 +51,7 @@ export const useLazyFindOneRecord = <T extends ObjectRecord = ObjectRecord>({
await findOneRecord({
variables: { objectRecordId },
fetchPolicy,
client: apolloCoreClient,
onCompleted: (data) => {
const record = getRecordFromRecordNode<T>({
recordNode: data[objectNameSingular],
@@ -1,5 +1,6 @@
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { MAX_SEARCH_RESULTS } from '@/command-menu/constants/MaxSearchResults';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
@@ -33,6 +34,8 @@ export const useObjectRecordSearchRecords = ({
objectNameSingular,
});
const apolloCoreClient = useApolloCoreClient();
const { enqueueSnackBar } = useSnackBar();
const { data, loading, error, previousData } = useSearchQuery({
@@ -48,6 +51,7 @@ export const useObjectRecordSearchRecords = ({
includedObjectNameSingulars: [objectNameSingular],
},
fetchPolicy: fetchPolicy,
client: apolloCoreClient,
onError: (error) => {
logError(
`useSearchRecords for "${objectMetadataItem.namePlural}" error : ` +
@@ -1,17 +1,17 @@
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { getAggregateQueryName } from '@/object-record/utils/getAggregateQueryName';
import { useApolloClient } from '@apollo/client';
export const useRefetchAggregateQueries = ({
objectMetadataNamePlural,
}: {
objectMetadataNamePlural: string;
}) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const refetchAggregateQueries = async () => {
const queryName = getAggregateQueryName(objectMetadataNamePlural);
await apolloClient.refetchQueries({
await apolloCoreClient.refetchQueries({
include: [queryName],
});
};
@@ -1,7 +1,6 @@
import { useApolloClient } from '@apollo/client';
import { triggerUpdateRecordOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffect';
import { apiConfigState } from '@/client-config/states/apiConfigState';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -36,7 +35,7 @@ export const useRestoreManyRecords = ({
const mutationPageSize =
apiConfig?.mutationMaximumAffectedRecords ?? DEFAULT_MUTATION_BATCH_SIZE;
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -73,7 +72,7 @@ export const useRestoreManyRecords = ({
const cachedRecords = batchedIdsToRestore
.map((idToRestore) =>
getRecordFromCache(idToRestore, apolloClient.cache),
getRecordFromCache(idToRestore, apolloCoreClient.cache),
)
.filter(isDefined);
@@ -109,13 +108,13 @@ export const useRestoreManyRecords = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: computedOptimisticRecord,
recordGqlFields,
objectPermissionsByObjectMetadataId,
});
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecord: cachedRecordWithConnection,
updatedRecord: optimisticRecordWithConnection,
@@ -125,7 +124,7 @@ export const useRestoreManyRecords = ({
});
}
const restoredRecordsResponse = await apolloClient
const restoredRecordsResponse = await apolloCoreClient
.mutate({
mutation: restoreManyRecordsMutation,
variables: {
@@ -168,14 +167,14 @@ export const useRestoreManyRecords = ({
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: cachedRecord,
recordGqlFields,
objectPermissionsByObjectMetadataId,
});
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecord: optimisticRecordWithConnection,
updatedRecord: cachedRecordWithConnection,
@@ -1,7 +1,6 @@
import { useApolloClient } from '@apollo/client';
import { triggerUpdateRecordOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffect';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
@@ -37,7 +36,7 @@ export const useUpdateOneRecord = <
objectNameSingular,
recordGqlFields,
}: useUpdateOneRecordProps) => {
const apolloClient = useApolloClient();
const apolloCoreClient = useApolloCoreClient();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
@@ -75,7 +74,7 @@ export const useUpdateOneRecord = <
objectMetadataItem,
currentWorkspaceMember: currentWorkspaceMember,
recordInput: updateOneRecordInput,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItems,
objectPermissionsByObjectMetadataId,
});
@@ -118,14 +117,14 @@ export const useUpdateOneRecord = <
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: computedOptimisticRecord,
recordGqlFields,
objectPermissionsByObjectMetadataId,
});
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecord: cachedRecordWithConnection,
updatedRecord: optimisticRecordWithConnection,
@@ -142,7 +141,7 @@ export const useUpdateOneRecord = <
recordInput: updateOneRecordInput,
}),
};
const updatedRecord = await apolloClient
const updatedRecord = await apolloCoreClient
.mutate({
mutation: updateOneRecordMutation,
variables: {
@@ -185,7 +184,7 @@ export const useUpdateOneRecord = <
updateRecordFromCache({
objectMetadataItems,
objectMetadataItem,
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
record: {
...cachedRecord,
...buildRecordFromKeysWithSameValue(
@@ -198,7 +197,7 @@ export const useUpdateOneRecord = <
});
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
cache: apolloCoreClient.cache,
objectMetadataItem,
currentRecord: optimisticRecordWithConnection,
updatedRecord: cachedRecordWithConnection,