apollo-link
apollo-link copied to clipboard
How to abort next operation?
Hello madams and sirs,
I need to do some guard based on operation name. If name matches, abort the operation. How does one do this?
In other words, what is the opposite of forward(operation)?
Example code:
const guardLink = new ApolloLink((operation, forward) => {
if (operation.operationName === 'getGames') {
// how to abort the next operation here and continue to the one after the next?
return forward(null)
}
return forward(operation)
})
you need to return an error Observable on your operation link
smth like this
getMyAbortableLink() {
return new ApolloLink((operation, forward) => {
const ok = // check your condition here
if (ok) {
return forward(operation);
} else {
return new Observable((subscriber) => {
subscriber.error(some error result);
});
}
}