-
Hello, I read the docs but I don't see any way to invalidate document. For example when I do this; updates: {
Mutation: {
login: ({ login }, _, cache) => {
cache.invalidate({ __typename: "User", id: login.id });
},
logout: (_, __, cache) => cache.updateQuery({ query: GetUserDocument }, (data: Query["me"]) => null),
},
}, Neither does work correctly. In App.vue; <script lang="ts" setup>
import { useGetUserQuery } from "./hooks/graphql";
const { data: user } = useGetUserQuery();
watch( () => user.value, () => console.log("user is changed"));
watch( () => user.value, () => console.log("user is changed: deep"), { deep: true } );
// They are called only at the beginning.
</script> In Login component const submit = () => {
loginMutation({ data }); // does not trigger useGetUserQuery again.
};
const logout = () => {
logoutMutation({}); // does not change **user** of **useGetUserQuery**
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don quite know what your query is obviously, but when you login, you can't invalidate what's already being returned. So, if your login mutation returns a If you're only after updating a single field, e.g. |
Beta Was this translation helpful? Give feedback.
I don quite know what your query is obviously, but when you login, you can't invalidate what's already being returned. So, if your login mutation returns a
User
there's in theory no need to invalidate anything for the query that contains the user, unless the ID changes, which means you could usecache.link
to update the fieldIf you're only after updating a single field, e.g.
Query.user
without arguments, let's say then you'd likely want to use:cache.invalidate('Query', 'user')
If you're only looking to update said field you could use
cache.link
on login to make sure the key is up-to-date using:cache.link('Query', 'user', login)