Apollo Link to Short Circuit Request

What is best practice for short circuiting a request from happening? For context, we need to be able to stop a mutation from happening based off of user information. We could go throughout our app and add checks to every place we make a mutation or we were thinking of creating a new Apollo Link that returns nothing if the user shouldn’t be able to make that mutation call. The Apollo Link idea is based on the docs linked below.

If a non-terminating custom link’s request handler doesn’t return forward(operation) , the link chain ends and the associated GraphQL operation is not executed.

This will change a bit - generally, yes, a link doesn’t need to call forward, but in AC 4.0, that link will still have to return an Observable instance.

So you could e.g. return an Observable that just emits { errors: [{ message: "Mutation not allowed" }] }.
If you don’t go for an error, what you return has to be a valid response shape to your mutation.

1 Like

Thanks for the reply and the insight into AC 4.0! The solution you proposed is much more explicit than just returning nothing in an Apollo Link.