Skip to content

Instantly share code, notes, and snippets.

@czbaker
Created June 2, 2016 18:28
Show Gist options
  • Select an option

  • Save czbaker/2d21139fb711586d1bbb931a71fd262a to your computer and use it in GitHub Desktop.

Select an option

Save czbaker/2d21139fb711586d1bbb931a71fd262a to your computer and use it in GitHub Desktop.
import ApolloClient, { createNetworkInterface } from 'apollo-client';
const networkInterface = createNetworkInterface('/graphql');
networkInterface.use({
applyMiddleWare(req, next) => {
if (!req.options.header) {
req.options.header = {}; // Create the header object if needed.
}
req.options.header.authorization = localStorage.getItem('token') ? localStorage.getItem('token') : null;
next();
}
});
const client = new ApolloClient({
networkInterface,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment