如何解决Vue.js Apollo graphql将请求发送到localhost而不是特定端点
我配置了多客户端vue阿波罗,但由于某种原因,它仅向本地主机发送请求。但是,我从未指定本地主机端点。这是我的配置文件
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)",e.message);
}
}
我根据文档编辑了此文件。为什么apollo会将请求发送到错误的端点以及如何解决?我根据文档编辑了该文件。为什么apollo会将请求发送到错误的端点以及如何解决? 我根据文档编辑了该文件。为什么apollo会将请求发送到错误的端点以及如何解决?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。