vue.js - Apollo graphql 在 localhost 上发送请求,而不是指定 ep
问题描述
我配置了一个多客户端 vue apollo,但由于某种原因,它只向 localhost 发送请求。但是,我从未指定 localhost 端点。这是我的配置文件
vue-apollo.js:
import Vue from "vue";
import VueApollo from "vue-apollo";
import {
createApolloClient,
restartWebsockets
} from "vue-cli-plugin-apollo/graphql-client";
Vue.use(VueApollo);
const AUTH_TOKEN = "apollo-token";
const httpsEndpoint =
process.env.VUE_APP_GRAPHQL_HTTPS || "https://myst.endpoint.prod/graphql";
export const filesRoot =
process.env.VUE_APP_FILES_ROOT ||
httpsEndpoint.substr(0, httpsEndpoint.indexOf("/graphql"));
Vue.prototype.$filesRoot = filesRoot;
const defaultOptions = {
httpsEndpoint,
wssEndpoint:
process.env.VUE_APP_GRAPHQL_WSS || "wss://myst.endpoint.prod/graphql",
tokenName: AUTH_TOKEN,
persisting: false,
websocketsOnly: false,
ssr: false
};
const clientAOptions = {
httpsEndpoint: "https://myst.endpoint.prod/graphql"
};
const clientBOptions = {
httpsEndpoint: "https://mynd.endpoint.prod/graphql"
};
export function createProvider(options = {}) {
const createA = createApolloClient({
...defaultOptions,
...clientAOptions
});
const createB = createApolloClient({
...defaultOptions,
...clientBOptions
});
const a = createA.apolloClient;
const b = createB.apolloClient;
const apolloProvider = new VueApollo({
clients: {
a,
b
},
defaultClient: a,
defaultOptions: {
$query: {
}
},
errorHandler(error) {
console.log(
"%cError",
"background: red; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;",
error.message
);
}
});
return apolloProvider;
}
export async function onLogin(apolloClient, token) {
if (typeof localStorage !== "undefined" && token) {
localStorage.setItem(AUTH_TOKEN, token);
}
if (apolloClient.wsClient) restartWebsockets(apolloClient.wsClient);
try {
await apolloClient.resetStore();
} catch (e) {
console.log("%cError on cache reset (login)", "color: orange;", e.message);
}
}
export async function onLogout(apolloClient) {
if (typeof localStorage !== "undefined") {
localStorage.removeItem(AUTH_TOKEN);
}
if (apolloClient.wsClient) restartWebsockets(apolloClient.wsClient);
try {
await apolloClient.resetStore();
} catch (e) {
console.log("%cError on cache reset (logout)", "color: orange;", e.message);
}
}
我根据文档编辑了这个文件。为什么 apollo 将请求发送到错误的端点以及如何修复它?我根据文档编辑了这个文件。为什么 apollo 将请求发送到错误的端点以及如何修复它?我
解决方案
推荐阅读
- ansible - 有没有办法使用 Ansible 获取 vSphere 清单树?
- php - 如何使用原生 sftp 函数和 PHP 中的 fwrite 提高文件上传的性能
- typescript - 是否可以允许对象值作为类型?
- python - 重塑图像的numpy数组会产生额外的维度
- google-cloud-platform - 根据地理位置将用户重定向或转发到适当的子域
- python - 协助 Keras 编写噪声检测脚本
- python - 冒泡排序算法输入不起作用(Python)
- flutter - 在 null 上调用了方法“add”并尝试调用:add(String)
- eclipse - 仅 maven 出错:NoClassDefFoundError: feign/codec/Encoder
- c# - 将 C++ 回调函数传递给 COM 进程外方法