perf: apply record optimistic effects with cache.modify on mutation (#3540)
* perf: apply record optimistic effects with cache.modify on mutation Closes #3509 * refactor: return early when created records do not match filter * fix: fix id generation on record creation * fix: comment filtering behavior on record creation * Fixed typing error * refactor: review - use ?? * refactor: review - add variables in readFieldValueToSort * docs: review - add comments for variables.first in triggerUpdateRecordOptimisticEffect * refactor: review - add intermediary variable for 'not' filter in useMultiObjectSearchMatchesSearchFilterAndToSelectQuery * refactor: review - add filter utils * fix: fix tests --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -1,17 +1,23 @@
|
||||
// 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) => {
|
||||
export const parseApolloStoreFieldName = <
|
||||
Variables extends Record<string, unknown>,
|
||||
>(
|
||||
storeFieldName: string,
|
||||
) => {
|
||||
const matches = storeFieldName.match(/([a-zA-Z][a-zA-Z0-9 ]*)\((.*)\)/);
|
||||
|
||||
if (!matches?.[1]) return {};
|
||||
|
||||
const [, fieldName, stringifiedVariables] = matches;
|
||||
const [, , stringifiedVariables] = matches;
|
||||
const fieldName = matches[1] as string;
|
||||
|
||||
try {
|
||||
const variables = stringifiedVariables
|
||||
? (JSON.parse(stringifiedVariables) as Record<string, unknown>)
|
||||
? (JSON.parse(stringifiedVariables) as Variables)
|
||||
: undefined;
|
||||
|
||||
return { fieldName, variables };
|
||||
|
||||
Reference in New Issue
Block a user