Skip to content

Instantly share code, notes, and snippets.

@dfischer
Forked from czbaker/apollo-client.js
Created June 3, 2016 04:53
Show Gist options
  • Save dfischer/c774503b80465742a066f71f3776adda to your computer and use it in GitHub Desktop.
Save dfischer/c774503b80465742a066f71f3776adda 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