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 (将#修改为@)