Get handle on client from query result? #1222
-
|
We have a I don't see it but thought I'd ask. Is there something similar in Urql? export const useMe = (query = GET_ME, fetchPolicy = 'cache-first') => {
let me;
const meQuery = useQuery(query, { fetchPolicy });
if (meQuery.error) {
console.log('useMe QUERY ERROR ==>', meQuery.error);
}
const user = meQuery.data?.user[0];
if (user) {
// This is a convenience function we're passing along with me.
// It allows the consumer the ability to call me.update with an
// array of new values.
const update = (values: meValuesType) => {
meQuery.client.mutate({ // 👈 possible with Urql ❔
mutation: UPDATE_ME,
variables: { id: user.id, changes: { ...values } },
});
meQuery.refetch();
};
me = {
...user,
update,
refetch: meQuery.refetch,
};
}
return me;
}; |
Beta Was this translation helpful? Give feedback.
Answered by
JoviDeCroock
Dec 10, 2020
Replies: 1 comment 1 reply
-
|
You would have to make a |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
GollyJer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You would have to make a
useMutationhook so this would look like: