71c377484e
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>
29 lines
712 B
TypeScript
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 };
|
|
};
|