假设您尝试访问多个客户端,而不仅仅是产品和开发的不同客户端,这可能会有所帮助,就像我在当前项目中使用的一样。
apollo: {
includeNodeModules: true, // optional, default: false (this includes graphql-tag for node_modules folder)
authenticationType: 'Basic', // optional, default: 'Bearer'
errorHandler: '~/apollo/customErrorHandler',
clientConfigs: {
default:
{
httpEndpoint:
'https://me.something.com/api/graphql/query?token=******',
httpLinkOptions: {
credentials: 'same-origin'
}
},
// '~/apollo/clientConfig.js',
otherClient: {
httpEndpoint:
'https://second-endpoint-gql.herokuapp.com/v1/graphql',
httpLinkOptions: {
credentials: 'same-origin'
}
}
}
},
现在您需要做的就是让您的查询正常进行,但不同之处在于 vue 组件。
/gql/allCars.gql
{
allCars {
id
make
model
year
}
}
默认调用将像往常一样进行:
<script>
import allcars from '~/gql/users'
export default {
apollo: {
allcars: {
prefetch: true,
query: allcars
}
},
filters: {
charIndex (i) {
return String.fromCharCode(97 + i)
}
},
head: {
title: ....
},
data () {
return {
...
}
}
}
</script>
调用您需要添加 $client 的辅助端点:
<script>
import allcars from '~/gql/users'
export default {
apollo: {
$client: 'otherClient',
allcars: {
prefetch: true,
query: allcars
}
},
filters: {
charIndex (i) {
return String.fromCharCode(97 + i)
}
},
head: {
title: ....
},
data () {
return {
...
}
}
}
</script>
毫无价值的是,阿波罗调试器似乎只查询阿波罗配置中端点列表中的最后一个端点,在我的例子中是“其他客户端”。
参考我上面的集成是怎么来的:Vue 多客户端