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.

update fails if a query has not yet been executed

See original GitHub issue

Not sure if this is a bug or intended behaviour, however, it doesn’t work for my use case. The same thing has been reported (and fixed) for refetchQueries (see #690), although I do realise that this case is different.

Intended outcome: I’m executing a mutation query which afterwards requires a manual update of the store. However, I cannot guarantee that the query I want to update has been run with the exact parameters already. If the query has not yet been executed I don’t care about the update, since the result must be fetched from the server anyway.

(A simple example to illustrate the issue: consider a simple to do app. The user can view pending tasks and completed tasks. Also, the user can mark a pending task as done. The main view only shows (and queries for) pending tasks, since always loading the large number of completed tasks would impact performace. If the user marks a pending task as done, the query for completed tasks should be updated, but may not have been executed before.)

Actual outcome: I’m using update to manually update the store. If the query I want to update has not yet been run, proxy.readQuery() will throw an error.
For my use case it would be better to return null, so that I can decide myself what to do in this case (which would be to just do nothing). I realise I could achieve this with try/catch, but this feels wrong.

How to reproduce the issue: Execute a mutation query with an update method, which tries to read a query from the store that has not yet been executed (using the DataProxy’s readQuery() method).

Version

  • apollo-client@1.7.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
janaleiblecommented, Oct 22, 2017

Also, it feels wrong to manage control flow through try/catch in this way – a query that hasn’t been executed yet is not necessarily an exception, it may well be a valid use case.
An alternative would be to offer a method returning a boolean indicating whether the query has already been executed that could then be used with an if block.

3reactions
tsvetanncommented, Jan 14, 2018

The same problem exists in "apollo-client": "2.0.4"

The only decent workaround I found is using apollo-link-state and predefining defaults for the said query otherwise it just throws which is not ideal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to safely update Apollo client cache after mutation if ...
The cache update for the "Drafts" query works as expected, because the query has already been executed and data stored in the cache....
Read more >
How to check if update query was executed or not in MySQL?
I suspect you want the ROW_COUNT() function. UPDATE table SET table.name = "Anthony" WHERE table.id = 3; SELECT CASE WHEN ROW_COUNT() > 0 ......
Read more >
Error messages when you perform an UPDATE, INSERT, or ...
OpenQuery requires a result set to be returned, but UPDATE, DELETE, and INSERT statements that are used with OpenQuery do not return a...
Read more >
How can I track the execution of PL/SQL and SQL? - Ask TOM
you can certain query v$transaction (a view not normally available to most people) to see if you are in a transaction - yes....
Read more >
get-query-execution — AWS CLI 1.27.37 Command Reference
Returns information about a single execution of a query if you have access ... does not match the actual owner of the Amazon...
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