Files
twenty/packages/twenty-front/src/pages/settings/applications/hooks/useUpdateOneApplicationVariable.ts
T
Nicolas Besnard 71c377484e fix(front): keep app variable cache in sync after update (#20861)
Updating an application variable in Workspace / Applications / <App> /
Settings persisted server-side but the Apollo cache kept the old value.
Switching tabs unmounted the settings tab, and remounting reseeded the
input from the stale cache — only a full refresh showed the new value.

Mutation now writes the new value into the ApplicationVariable entity
via cache.modify, so FindOneApplication reflects the change immediately.
Hook + table updated to pass the variable id through.

Adds a hook test that pre-seeds the cache and asserts the cached value
after the mutation.

NOTE: saving the plain value in Apollo's cache might not be the best
approach here

---------

Co-authored-by: martmull <martmull@hotmail.fr>
2026-06-01 08:14:28 +00:00

29 lines
712 B
TypeScript

import { useMutation } from '@apollo/client/react';
import {
FindOneApplicationDocument,
UpdateOneApplicationVariableDocument,
} from '~/generated-metadata/graphql';
export const useUpdateOneApplicationVariable = () => {
const [mutate] = useMutation(UpdateOneApplicationVariableDocument);
const updateOneApplicationVariable = async ({
key,
value,
applicationId,
}: {
key: string;
value: string;
applicationId: string;
}) => {
return await mutate({
variables: { key, value, applicationId },
refetchQueries: [
{ query: FindOneApplicationDocument, variables: { id: applicationId } },
],
});
};
return { updateOneApplicationVariable };
};