svelte: error when mutation is in function
See original GitHub issueHi guys,
I’m having a hard time trying make a simple login mutation work, here’s the code:
import {
initClient,
mutate
} from '@urql/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 Function called outside component initialization
, the only way to make it work is to do something like $: 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 !
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
svelte: error when mutation is in function · Issue #795 - GitHub
Hi guys, I'm having a hard time trying make a simple login mutation work, here's the code: import { initClient, mutate } from...
Read more >Mutations | Svelte Query | SvelteStack
error - If the mutation is in an isError state, the error is available via the error property. data - If the mutation...
Read more >Svelte Query Mutations • REPL • Svelte
1. <script> ; 2. import { QueryClient, useMutation, useQuery } from '@sveltestack/svelte-query@1.1.0'; ; 3. import { mutationOptions, ...
Read more >Mutations | Svelte Relay - GitHub Pages
To set up a mutation in Svelte Relay, you can use the getMutation() function. This function accepts a GraphQL query, and returns a...
Read more >Svelte with Apollo GraphQl - Mutation is not getting triggered
async/await async function signInAction() { try { const result = await ... catch (error) { console.log(error); } } // then/catch function ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Currently the
mutate
helper in Svelte runs immediately as we’re still figuring out patterns.However, if you call a mutation programmatically you can use
getClient()
and callclient.mutation
, like so: https://formidable.com/open-source/urql/docs/concepts/core-package/#one-off-queries-and-mutationsWe’re still working on idiomatic Svelte APIs so this one’s also on our list to figure out what the best way forward is
Edit: For context, the previous API had a lazy promise. Currently I’m thinking we could just return a closure like in the React API
I hope I won’t forget, but I’ll come back to you once we’ve got an idea on how to improve this Svelte API 👍