question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

svelte: mutate in a try catch

See original GitHub issue

Using @urql/svelte I cannot use this simple code:

mutate({
  query: DELETE_TODO,
  variables: { id: todoID }
})

The mutation doesn’t start at all.

It just works like this:

mutate({
  query: DELETE_TODO,
  variables: { id: todoID }
}).then()

or like this:

async function callMutation() {
  await mutate({
    query: DELETE_TODO,
    variables: { id: todoID }
  })
}

but I wanna use the first one in a try {} catch {}.

Is it possible?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kittencommented, Apr 27, 2020

The issue of lazy promises has been fixed; as per the global error exchange, I suppose if you already have one there isn’t much special to consider here? I’ll close for now but I think you had another thread going on Spectrum about this, right? 😃 https://github.com/FormidableLabs/urql/pull/758

0reactions
kittencommented, Apr 26, 2020

The lazy promise was a mistake based on some assumptions so that shouldn’t be hard for us to fix (meanwhile you can just use async-await or call then as you discovered.

Are you putting your error codes in extensions? If so you can identify your errors using res.error.graphQLErrors.some(x => x.extensions.code === A_CODE) where you define extensions.code or some other property

Read more comments on GitHub >

github_iconTop Results From Across the Web

svelte: mutate in a try catch #756 - urql-graphql/urql - GitHub
The mutation doesn't start at all. I'll take a look at that, that seems unusual;. but I wanna use the first one in...
Read more >
Mutations | Svelte Relay - GitHub Pages
If an error occurs in the mutation, the promise will be rejected with the error. You can use try/catch to handle these errors....
Read more >
Apollo Mutation | Svelte Apollo GraphQL Tutorial - Hasura
We will use the mutation from Svelte Apollo in Svelte app as an example to insert new data and update cache locally using...
Read more >
Docs • Svelte
Complete documentation for Svelte.
Read more >
Dynamic behavior in Svelte: working with variables and props
To prove it, go to that array, and try changing some of the to-do object's completed property values, and even add a new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found