Vue-apollo: Is there interceptor or middleware here?

Created on 27 Jun 2018  路  5Comments  路  Source: vuejs/vue-apollo

How can i interception the http request锛宖or example 401.

All 5 comments

Thank you very much.

What I intend to do is intercept all GraphQL queries to check on a common error my server throws for certain reasons, eg: USER NOT FOUND

Then act on it globally in the frontend app.

I am still wondering how to do this, any help? I guess this could be great if written in the Docs also.

Ok thanks I saw this:

import { ApolloLink } from "apollo-link";
import { createHttpLink } from "apollo-link-http";
import { onError } from "apollo-link-error";

import { logout } from "./logout";

const httpLink = createHttpLink({ uri: "/graphql" });
const errorLink = onError(({ networkError }) => {
  if (networkError.statusCode === 401) {
    logout();
  }
});

// use with apollo-client
const link = errorLink.concat(httpLink);

going to give it a try.

@emahuni

import { logout } from "./logout";

Can I see your logout ?

I need to access the Vuex store but unsure.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anymost picture anymost  路  3Comments

seanaye picture seanaye  路  3Comments

ais-one picture ais-one  路  4Comments

Akryum picture Akryum  路  3Comments

sadhakbj picture sadhakbj  路  3Comments