0

I have an ApolloLink setup for the AWSAppSyncClient in my React project to check if the user is authorized to make the graphql request. If the user is not authorized then, link should not invoke the forward method rather just return an Error for unauthorized access (making it a terminating link).

I tried returning the plain Error response (also tried it with Observable.of), but the request doesn't resolves but keeps on to retry the request on an endless loop.

Need a better solution to implement it.

const authLink = new ApolloLink((operation, forward) => {
  const { operationName } = operation;
  if (checkIfNotAuthorized(operationName)) {
    const error = new Error('Access denied');
    return { errors: [error], data: null };
  }
  return forward(operation);
});
Nitesh
  • 1
  • 2

0 Answers0