Я использую заголовки для аутентификации с помощью Apollo Client. Следующее работало нормально:
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