<commit_before>import { ApolloClient, createNetworkInterface, ApolloProvider } from 'react-apollo';
import { GRAPHQL_API_URL } from './constants';
import { getJwtToken, haveJwtToken } from './utils/auth';


/* eslint-disable no-param-reassign */
const authMiddleware = {
  applyMiddleware(req, next) {
    if (!haveJwtToken()) next();

    if (!req.options.headers) {
      req.options.headers = {};
    }

    req.options.headers.authorization = `Bearer ${getJwtToken()}`;
    next();
  },
};
/* eslint-enable no-param-reassign */

const createApolloClient = () => {
  const networkInterface = createNetworkInterface({
    uri: GRAPHQL_API_URL,
    queryDeduplication: true,
  });
  networkInterface.use([authMiddleware]);

  return new ApolloClient({
    networkInterface,
    reduxRootSelector: (state) => state.get('apollo'),
    connectToDevTools: process.env.NODE_ENV !== 'production',
  });
};

const client = createApolloClient();
export { ApolloProvider, client };<commit_msg>Logout if graphql endpoints returns status code 403 or 401<commit_after>import { ApolloClient, createNetworkInterface, ApolloProvider } from 'react-apollo';
import { browserHistory } from 'react-router';

import { GRAPHQL_API_URL } from './constants';
import { getJwtToken, haveJwtToken, deleteJwtToken } from './utils/auth';
import { loginPage } from './local-urls';


/* eslint-disable no-param-reassign */
const authMiddleware = {
  applyMiddleware(req, next) {
    if (!haveJwtToken()) next();

    if (!req.options.headers) {
      req.options.headers = {};
    }

    req.options.headers.authorization = `Bearer ${getJwtToken()}`;
    next();
  },
  applyAfterware({ response }, next) {
    response.clone().json().then((body) => {
      if (body.errors && body.errors.some((e) => e.status === 401 || e.status === 403)) {
        deleteJwtToken();
        browserHistory.replace(loginPage(browserHistory.getCurrentLocation().pathname));
      } else {
        next();
      }
    });
  },
};
/* eslint-enable no-param-reassign */

const createApolloClient = () => {
  const networkInterface = createNetworkInterface({
    uri: GRAPHQL_API_URL,
    queryDeduplication: true,
  });
  networkInterface.use([authMiddleware]);
  networkInterface.useAfter([authMiddleware]);

  return new ApolloClient({
    networkInterface,
    reduxRootSelector: (state) => state.get('apollo'),
    connectToDevTools: process.env.NODE_ENV !== 'production',
  });
};

const client = createApolloClient();
export { ApolloProvider, client };
{'fraction_non_alphanumeric': 0.1506576325229175, 'fraction_numerical': 0.004782781984854523, 'mean_word_length': 4.050301810865191, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2794448', 'n_tokens_mistral': 789, 'n_tokens_neox': 754, 'n_words': 152}