menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
# All channels
view-forward
# General
view-forward
# Apollo Angular
view-forward
# Announcements
view-forward
# Apollo Android
view-forward
# Apollo Client
view-forward
# Apollo iOS
view-forward
# Apollo Link
view-forward
# Apollo Link Rest
view-forward
# Local State
view-forward
# Apollo Studio
view-forward
# Apollo Server
view-forward
# Apollo Tooling
view-forward
# Contributing
view-forward
# Docs
view-forward
# Events
view-forward
# GraphQL Tools
view-forward
# Jobs
view-forward
# Random
view-forward
# React Apollo
view-forward
# Showcase
view-forward
# Subscriptions
view-forward
# Testing
view-forward
# Vue Apollo
view-forward
Team

How do I "listen" to every mutation result?

May 10, 2020 at 8:04pm

How do I "listen" to every mutation result?

May 10, 2020 at 8:04pm
I want to see if there is a specific property or node type returned by the server, and if so, update my state. The manual way would be to after every mutation call pass the returned data to my DoSomethingIfMutationHasXService. Is there a solution that is less cumbersome?
I was thinking about somehow listening to each mutation result in the service itself. Any ideas? How would you go about doing that? :)

May 10, 2020 at 9:19pm
You could use a custom link
  • reply
  • like
const yourLink = new ApolloLink((operation, forward) => {
return forward(operation).map((result) => {
const { data, errors } = result
// do whatever with the result
return result;
})
});
like-fill
1
  • reply
  • like

June 9, 2020 at 10:32pm
I was actually looking for a higher level solution, but you are right, I can create my own api for it. Thanks for pointing out the lower level options. :)
  • reply
  • like