-
Hey, I'm trying to get makeVar (reactive variables) working, but it looks like it requires React's context system to be available? Anything in the works for Vue-Apollo? Or is there a way to trigger Apollo to re-query some other "Vue" way? I'm a bit nooby to all this, so go easy on me. 😁 Scott |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Ok. I think I solved this and it was fairly simple. Not sure it is "kosher". What I did was create a ref and make it exportable. export const userLoggedInRef = ref(false) In the Apollo Link, I did this: if (message.includes('Invalid Token')) {
LocalStorage.set('token', '')
userLoggedInRef.value = false
forward(operation)
}
}) where In the Apollo client call for the cache, I added this: cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
userLoggedIn() {
return userLoggedInRef.value;
},
},
},
},
}), I'm using the ref everywhere, but theoretically, I could query for the current value too...? And for instance in my component for logging in, I have: const { mutate: login } = useMutation(Login_Mutation,
() => ({
variables: {
username: username.value,
password: password.value
},
update: async (cache , { data: { login: { accessToken} } }) =>{
console.log('this is the data: ', accessToken)
if (!accessToken) {
console.log('oops, you need to log in with the right credentials') // TODO: need to do a proper error to the user
} else {
$q.localStorage.set('token', accessToken)
userLoggedInRef.value = true
onDialogHide()
}
}
})) Using the ref is just like Apollo's Scott |
Beta Was this translation helpful? Give feedback.
-
No, it doesn't rely on React. |
Beta Was this translation helpful? Give feedback.
No, it doesn't rely on React.