我有一个使用Apollo进行GraphQL查询和突变的Vue应用程序。 Apollo客户端设置如下:
import ApolloClient, { createNetworkInterface } from 'apollo-client';
const networkInterface = createNetworkInterface({ uri: '/graphql' });
networkInterface.use([{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}; // Create the header object if needed.
}
req.options.headers['authorization'] = localStorage.getItem('token') ? localStorage.getItem('token') : null;
next();
}
}]);
const client = new ApolloClient({
networkInterface,
});
当我登录我的API并获取访问令牌时,我必须刷新Apollo客户端的页面,以识别localStorage中现在存在令牌。为什么apollo没有在localStorage中检测到令牌?