嗨,我正在尝试使用auth标头在apollo中实现订阅。我一直遇到我收到CORS错误的问题。
似乎无法做到这一点。
这是我更改代码的精简版本:
const httpLink = new HttpLink({
uri: "http://localhost:4444/graphql",
fetchOptions: {
credentials: "include"
},
request: operation => {
const token = localStorage.getItem("token");
operation.setContext({
headers: {
Authorization: "Bearer " + token
}
});
},
onError: ({ networkError }) => {
if (networkError) {
console.log("Network Error:::", networkError);
}
}
});
const wsLink = new WebSocketLink({
uri: ws://localhost:4444/subscriptions,
options: {
reconnect: true
}
});
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === "OperationDefinition" && operation === "subscription";
},
wsLink,
httpLink
);
*注意,我正在尝试使用auth