【发布时间】:2020-06-29 13:13:03
【问题描述】:
const client = new ApolloClient({
uri,
onError: (e: any) => {
console.log('error: ', e); // Failed to fetch
console.log(e.operation.getContext()); // it does show it has x-abc-id
},
request: operation => {
const headers: { [x: string]: string } = {};
const accessToken = AuthService.getUser()?.accessToken;
const activeClientId = UserService.getActiveClientId();
headers['x-abc-id'] = activeClientId;
if (accessToken) headers['Authorization'] = `Bearer ${accessToken}`;
operation.setContext({ headers });
}
});
这里的问题是,当我只添加 Authorization 标头时,它会进行 POST 调用并显示预期的错误。
但是当我添加后端也期望的 x-abc-id 标头时,它只会进行 OPTIONS 调用(无后调用)
附:在邮递员上添加两个标题完全正常。
【问题讨论】:
标签: graphql apollo apollo-client apollo-boost