[英]In Apollo Nuxt, how do I access the non-default client in a method?
I'm using Apollo in a Nuxt app. 我在Nuxt应用程序中使用Apollo。 I'm trying to use my non-default client (Shopify) in a method.
我正在尝试在一种方法中使用我的非默认客户端(Shopify)。 Something like this ideally:
理想情况是这样的:
In my nuxt.config.js
I have Apollo setup like this: 在我的
nuxt.config.js
我具有如下的Apollo设置:
apollo: {
clientConfigs: {
default: {
httpEndpoint:
"http://example.com",
tokenName: "apollo-token",
persisting: false,
websocketsOnly: false
},
shopify: {
httpEndpoint:
"http://example.shopify.com",
tokenName: "apollo-token"
... etc...
}
}
}
And then in my component, I have this method: 然后在我的组件中,我有以下方法:
methods: {
createCheckout() {
this.$apollo.getClient("shopify")
.mutate({
mutation: this.checkoutQuery,
variables: {
variantId: this.selectedProduct.variantId,
quantity: this.selectedProduct.quantity
}
})
}
}}
This doesn't work, because getClient()
only returns the default client (WordPress in this case). 这不起作用,因为
getClient()
仅返回默认客户端(在这种情况下为WordPress)。 So how do I get access to the other client in a method? 那么,如何通过一种方法访问其他客户端呢?
Figured it out! 弄清楚了! The answer is this:
答案是这样的:
methods: {
createCheckout() {
this.$apollo.provider.clients.shopify
.mutate({
mutation: this.checkoutQuery,
variables: {
variantId: this.selectedProduct.variantId,
quantity: this.selectedProduct.quantity
}
})
}
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.