I'm working on an Angular project with Apollo and GraphQL. I have a mutation that updates a list of accounts with relevant details associated with it. After the successful mutation, I am using refetchqueries to query the API for updated list of accounts. Everything works till this part.
this.apollo.mutate({
mutation: mutationCreateNewAccount,
variables: {
accountNumber: this.accountNumber,
accountType: this.accountType,
routingNumber: this.routingNumber,
nameOfAcountHolder: this.name
},
refetchQueries: [{
query: queryAccounts,
variables: { accountNumber: this.accountNumber }
}]}).subscribe(({ data }) => console.log(data),
The 'data' for the subscription returns response from the mutation but is there a way I could use the data returned by 'queryAccounts' which is also run as part of this mutation?
There seems to be a way to do this in react but I was unsuccessful to do something similar in Angular.
You mentioned there are ways to do it in react and which I don't think is true.
Let me explain how mutations work in Apollo.
apollo.mutate()
with refetchQueries
optionconsole.log(data)
)refetchQueries
starts a new HTTP request and runs against the server.I explained it here, in docs: https://www.apollographql.com/docs/angular/features/cache-updates.html#after-mutations
Basically, refetchQueries is not to fetch or access data.