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 });
}
});
这里的问题是,当我只添加授权标头时,它会进行 POST 调用并显示预期的错误。
但是,当我添加后端也期望的x-abc-id标头时,它只会进行 OPTIONS 调用(没有后期调用)
PS 在邮递员上添加两个标题完全正常。