apollo-link icon indicating copy to clipboard operation
apollo-link copied to clipboard

How to abort next operation?

Open ts-23 opened this issue 4 years ago • 1 comments

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)
  })

ts-23 avatar Aug 01 '19 06:08 ts-23

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);
        });
      }
}

fetis avatar Mar 04 '20 14:03 fetis