fix: fix Relation field optimistic effect on Record update (#3352)
* fix: fix Relation field optimistic effect on Record update Related to #3099 * Fix lint * Fix * fix --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
21
packages/twenty-front/src/utils/parseApolloStoreFieldName.ts
Normal file
21
packages/twenty-front/src/utils/parseApolloStoreFieldName.ts
Normal file
@ -0,0 +1,21 @@
|
||||
// There is a feature request for receiving variables in `cache.modify`:
|
||||
// @see https://github.com/apollographql/apollo-feature-requests/issues/259
|
||||
// @see https://github.com/apollographql/apollo-client/issues/7129
|
||||
// For now we need to parse `storeFieldName` to retrieve the variables.
|
||||
export const parseApolloStoreFieldName = (storeFieldName: string) => {
|
||||
const matches = storeFieldName.match(/([a-zA-Z][a-zA-Z0-9 ]*)\((.*)\)/);
|
||||
|
||||
if (!matches?.[1]) return {};
|
||||
|
||||
const [, fieldName, stringifiedVariables] = matches;
|
||||
|
||||
try {
|
||||
const variables = stringifiedVariables
|
||||
? (JSON.parse(stringifiedVariables) as Record<string, unknown>)
|
||||
: undefined;
|
||||
|
||||
return { fieldName, variables };
|
||||
} catch {
|
||||
return { fieldName };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user