-
-
Save dfischer/c774503b80465742a066f71f3776adda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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