All files createApolloClient.js

57.14% Statements 8/14
12.5% Branches 1/8
100% Functions 1/1
57.14% Lines 8/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36      1x 1x       1x     1x                           1x 1x 1x 1x              
import { ApolloClient, createNetworkInterface } from 'react-apollo';
import fetch from 'isomorphic-fetch';
 
Eif (!process.browser) {
  global.fetch = fetch;
}
 
function create(data) {
  const networkInterface = createNetworkInterface({
    uri: data.endPoint,
  });
  const middleWares = [
    {
      applyMiddleware(req, next) {
        const token = data.oAuthToken;
        if (token) {
          if (!req.options.headers) {
            req.options.headers = {};
          }
          req.options.headers.authorization = token ? `Bearer ${token}` : null;
        }
        next();
      },
    },
  ];
  networkInterface.use(middleWares);
  const severNetworkInterface = createNetworkInterface({ uri: data.endPoint });
  severNetworkInterface.use(middleWares);
  return new ApolloClient({
    ssrMode: true,
    networkInterface: severNetworkInterface,
  });
}
 
export default create;