How can I refresh an Apollo query after redirecting to a new page using Vue Router?

Using Apollo mutation, I delete a resource on a page:

async delete () {
  await this.$apollo.mutate({
    mutation: orderDelete,
    variables: {
      id: this.order.id
    }
  })

  this.$emit('success')
}

This function is called by the success emitter:

onOrderDeleted () {
  this.closeModal('modalOrderDelete')

  this.$nextTick(() => {
    this.redirectToClient()
  })
},
redirectToClient () {
  this.$router.push({
    name: 'clients.show',
    params: { clientKey: this.clientKey }
  })
}

The issue arises when redirecting to the clients.show page, as the deleted order still appears until the whole page is refreshed.

I would like to find a way to trigger a query refresh upon redirection. It seems that Apollo's cache may be retaining outdated data and not updating it. Is there a way to programmatically update only the specific query cache upon redirection via Vue Router?

Note: The clients.show displays a list of orders and should reflect the deletion of the order upon redirection, which currently does not happen.

Answer №1

this.$apollo.mutate() offers additional functionalities that you may not have utilized:

The structure of the object is as follows:

this.$apollo.mutate({
  mutation: someGql,
  variables: {
    label: param1,
  },
  update: function(store, response) => {
    // guidance on updating the store
  },
  optimisticResponse: theResponseYouExpect,
})

It appears that while you sent the gql, you did not handle the response from the query (neither the actual server response nor the expected optimistic response upon success)

For more information on Vue Apollo mutation, please refer to this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Select the vocabulary items containing audio in an array using JavaScript

My goal is to enable clicking on words that are part of an array containing both texts and sounds. I found useful code at this link: Detect which word has been clicked on within a text. However, I am struggling to find a way to implement the feature of cl ...

Innovative Inter-Browser Link with a Distinct Shape

I am currently developing a web application that enables users to input content and then send it out to their phones. Everything is working smoothly, but I am facing an issue with the logo design. The logo in question is displayed as follows: On the left ...

What is the best way to handle the resolution of multiple promises as they complete?

Suppose I have three different promises each taking a varying amount of time to resolve - 1000ms, 2000ms, and 3000ms respectively. How can I simultaneously start all the promises and handle them as they get resolved? For instance: let quickPromise = new ...

Extract the content from a <Span> element without specifying its ID

Is there a way to make it so that when a user clicks on an HTML tag, the text is copied to their clipboard? I also need to ensure that this functionality does not apply to a specific tag ID/name as I am unable to add those to my span. Is there a way to aut ...

Guide to developing a form builder web application similar to Wufoo using JQuery and Rails!

Seeking guidance on incorporating a builder similar to Wufoo into a Rails 3 application with JQuery for client-side functionality. The goal is to enable users to create something (such as a form like in Wufoo) in offline mode and then save all edits to the ...

Creating interactive panorama hotspots with THREE.js SphereGeometry and DOMElements

After creating a WebGL 3D Panorama application using a SphereGeometry, PerspectiveCamera, and CanvasTexture, I am now trying to enhance the scene by adding "HotSpots" over specific areas of the SphereGeometry. However, I am facing difficulty in updating th ...

Unable to successfully interact with Paypal button using selenium automation

I'm facing an issue with Selenium where I am unable to click on the PayPal button. https://i.sstatic.net/Xx62H.png https://i.sstatic.net/lZg88.png Despite trying various methods recommended in the Selenium documentation, the button remains unrespon ...

Ways to pass properties to a class-based component

Currently, I am facing an issue while attempting to pass props to my class component. Here is how I passed the prop in the parent component: <Child contract={_contract}/> This is how I sent the props over. Within the child component, specifically w ...

Error: Unable to access 'subTree' property of null value

Can you help me understand this error? error message I encountered this issue when I inserted my filteredData variable within the tr tag of the table. <table id="table"> <tr> <th>First name</th> <th& ...

Implementing an object as a filter in an NG-repeat function

I've created multiple select dropdowns that are populated from a JSON file containing categories. My goal is to use the selections made by users in the dropdowns to filter a list of apps generated using ng-repeat. In my Plunker example http://plnkr. ...

Having trouble mapping my JSON to a Spring Boot @RequestBody POJO

I'm struggling with an issue where I have a hard-coded JSON object that is supposed to map to my POJO in Spring Controller, but I keep getting null values. I have double-checked my getters and setters, and everything seems to be correct. Can anyone he ...

Angular 2 - issues with datepicker functionality

Looking to add a datepicker to my application, I first attempted using bootstrap datepicker without success. Next, I tried ngBootstrap, but encountered the same issue - clicking the icon did not display the calendar. It seems as though the icon is not func ...

The behavior of Angular ngif remains consistent regardless of the variable

My service successfully loads a list of people from a local database, including a functional filter. However, I am having trouble displaying a loading wheel when applying the filter. Upon initializing my AppComponent, I set a variable called "loadingData" ...

Interactive selection choices not functioning properly within a pop-up window

I am currently working on a lightbox that contains a form with two choices, either Select UK or US. Each choice has its own list associated with it. Although I have successfully created the logic for this functionality, it seems to work fine outside of th ...

What is the process for binding an absolute path instead of a relative path in a script that includes Node and Perl calls?

In my script, there is a function with the following code: def tokenize(latex,kind='normalize'): output_file = './out.lst' input_file = './input_file.lst' cmd = "perl -pe 's|hskip(.*?)(cm\\|in& ...

Is it acceptable to post variables using AJAX for processing?

Is there a way to send data with AJAX using the code provided? It seems like the information is not being sent to the PHP file as intended. Here is the code snippet: $('#send').click(function(){ var pseudo = $('#psd').val(); }) ...

Retrieve the HTTP response code from an Ajax request within a PhantomJS website interaction

Our team is utilizing PhantomJS to capture a screenshot of our company's internal website. The script we are using is similar to the official examples provided by PhantomJS, but with an additional variable called waitTime (https://github.com/ariya/p ...

Tips for ensuring that the callback method waits for the completion of Google Markers creation

While developing my app with the Google Maps library, I encountered an issue either due to an unexplainable delay in creating markers or an unseen asynchronous problem. Here is a breakdown of the situation: The code retrieves the locations of Electric Cha ...

Tips for categorizing items retrieved from .getJSON based on their category property

Looking to display a menu of coffee items with their respective parent categories on the page? Here's how you can start: Category Title Item Item Item Item Category Title Item Item This is what my data model looks like: { "menuItems": [ ...

How does a database contribute to the functionality of a redux application?

Recently, I started exploring redux and finally understood the architecture behind it. In a single page redux application where all data is stored in a central store and updated through frontend actions, what purpose does the back-end and database serve? ...