【发布时间】:2018-07-29 13:30:12
【问题描述】:
我一直在使用标头与 Apollo 客户端进行身份验证。以下工作正常:
const middlewareAuthLink = new ApolloLink((operation, forward) => {
const token = localStorage.getItem('auth-token');
const authorizationHeader = token ? `Bearer ${token}` : null;
operation.setContext({
headers: {
authorization: authorizationHeader,
},
});
return forward(operation);
});
我正在切换到 Apollo Boost:https://dev-blog.apollodata.com/zero-config-graphql-state-management-27b1f1b3c2c3
const client = new ApolloClient({
uri: 'MY-GRAPHCOOL-API',
fetchOptions: {
credentials: 'include',
},
request: async operation => {
operation.setContext({
headers: {
authorization: 'sadfjadsfsd',
},
});
},
clientState: {
defaults: {
CurrentUserIsLoggedIn: {
__typename: 'CurrentUserIsLoggedIn',
value: false,
},
},
resolvers: {
Mutation: {
CurrentUserIsLoggedIn: (_, args, { cache }) => {
const data = {
CurrentUserIsLoggedIn: {
__typename: 'CurrentUserIsLoggedIn',
value: args.value,
},
};
cache.writeData({ data });
},
},
},
},
});
现在我收到一个错误,我的令牌没有被添加:
[Network error]: TypeError: operation.setContext is not a function
【问题讨论】:
-
我收到同样的错误
标签: apollo-client