【问题标题】:Single React JS project with multiple graphql URI Link具有多个 graphql URI 链接的单个 React JS 项目
【发布时间】:2022-05-05 00:36:08
【问题描述】:

您好,我是 ApolloClient 的新手,我不知道将多个 URI 链接作为 clint 传递,如果有人知道的话,我必须使用所有 URI 给我建议,接下来我必须做什么。

import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client';


// Set `RestLink` with your endpoint
const shopLink = new HttpLink({ uri: 'https://demo.vendure.io/shop-api' });

const cmsLink = new HttpLink({
  uri: 'https://cms.trylah.sg/graphql',
});
const vendureLink = new HttpLink({
  // Production
  //uri: 'https://demo.trylah.sg/shop-api',

  uri: process.env.REACT_APP_SHOP_API_URL || 'http://localhost:3000/shop-api',
  credentials: 'include',
});

export const client = new ApolloClient({
  link: shopLink,
  cache: new InMemoryCache(),
});

【问题讨论】:

    标签: graphql apollo-client react-apollo


    【解决方案1】:

    我遇到了类似的挑战并使用了 apollo-multi-endpoint-link 将 Apollo Link 设置为具有 API 指令以从多个端点获取数据。

    您可以看到一个工作原型in this repo,了解我是如何做到的。

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 2020-10-02
      • 2021-07-07
      • 1970-01-01
      • 2021-06-06
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多