作者:mobiledu2502910077 | 来源:互联网 | 2023-09-01 13:20
Hi guys,
I'm having a hard time trying make a simple login mutation work, here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import {
initClient,
mutate
} from '/svelte';
initClient({
url: 'https://graphql.fauna.com/graphql',
});
let promise;
let username = '';
let password = '';
const login = () => {
promise = mutate({
query: `
mutation (
$username: String!,
$password: String!
) {
loginUser(input: {
username: $username,
password: $password
})
}
`,
variables: {
username,
password,
}
});
} |
urql version & exchanges: v0.2.3
I don't understand why it just launches the mutation once and then it throws the error
1
| Function called outside component initialization |
, the only way to make it work is to do something like
1
| $: result = mutation(...) |
but it doesn't make sense, I don't want to run the mutation after each keystroke.
So please tell me, what I am doing wrong ?
Thank you !
该提问来源于开源项目:FormidableLabs/urql
I opened an issue here to better digging into: https://github.com/sveltejs/svelte/issues/4934.