[REFACTOR][BUG] Dynamically compute field to write in cache CREATE (#10130)

# Introduction
While importing records encountering missing expected fields when
writting a fragment from apollo cache

## Updates

### 1/ `createdBy` Default value
When inserting in cache in create single or many we will now make
optimistic behavior on the createdBy value

### 2/ `createRecordInCache` dynamically create `recordGrqlFields`
When creating an entry in cache, we will now dynamically generate fields
to be written in the fragment instead of expecting all of them. As by
nature record could be partial

### 3/ Strictly typed `RecordGqlFields`

# Conclusion
closes #9927
This commit is contained in:
Paul Rastoin
2025-02-13 17:43:54 +01:00
committed by GitHub
parent 58a62ec6f0
commit 5963c0f384
35 changed files with 495 additions and 107 deletions

View File

@ -24,6 +24,10 @@ export const useCreateOneRecordInCache = <T extends ObjectRecord>({
const apolloClient = useApolloClient();
return (record: ObjectRecord) => {
const recordGqlFields = generateDepthOneRecordGqlFields({
objectMetadataItem,
record,
});
const fragment = gql`
fragment Create${capitalize(
objectMetadataItem.nameSingular,
@ -33,9 +37,7 @@ export const useCreateOneRecordInCache = <T extends ObjectRecord>({
objectMetadataItems,
objectMetadataItem,
computeReferences: true,
recordGqlFields: generateDepthOneRecordGqlFields({
objectMetadataItem,
}),
recordGqlFields,
})}
`;