首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Vue阿波罗v4中设置多个客户端?

如何在Vue阿波罗v4中设置多个客户端?
EN

Stack Overflow用户
提问于 2022-05-18 20:54:12
回答 1查看 277关注 0票数 0

我有两个不同的服务器(graphql,rest),并试图在我的vue应用程序中设置多个客户端。

这是我的设置apollo.provider.js

代码语言:javascript
复制
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client/core'
import { RestLink } from 'apollo-link-rest';
import { provide } from 'vue'
import { ApolloClients } from '@vue/apollo-composable'

// HTTP connection to the API
const httpLink = createHttpLink({
    uri: 'https://reqres.in/graphql'
})

// Set `RestLink` with your endpoint
const restLink = new RestLink({ 
    uri: "https://reqres.in"
});

// Cache implementation
const cache = new InMemoryCache()

// Create the graphql client
const graphqlClient = new ApolloClient({
    cache: cache,
    link: httpLink
})

// Create the rest client
const restClient = new ApolloClient({
    cache: cache,
    link: restLink
})

export const provider = provide(ApolloClients, {
    default: graphqlClient,
    restClient: restClient
  })

这不起作用,但是我可以通过以下方式单独使用每个客户端

代码语言:javascript
复制
import { createApolloProvider } from '@vue/apollo-option'

export const provider = createApolloProvider({
    defaultClient: graphqlClient // or restClient
})

请帮助我理解如何使用两个客户。

EN

回答 1

Stack Overflow用户

发布于 2022-05-18 21:34:45

原来我把“选项API”和“组合API”混为一谈。

考虑到我的安装程序使用了"options“,这个解决方案可以工作。

代码语言:javascript
复制
export const provider = createApolloProvider({
    clients: {
        graphqlClient,
        restClient
    },
    defaultClient: graphqlClient,
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72295871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档