繁体   English   中英

在Apollo Nuxt中,如何使用方法访问非默认客户端?

[英]In Apollo Nuxt, how do I access the non-default client in a method?

我在Nuxt应用程序中使用Apollo。 我正在尝试在一种方法中使用我的非默认客户端(Shopify)。 理想情况是这样的:

在我的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...
        }
    }
}

然后在我的组件中,我有以下方法:

methods: {
        createCheckout() {
            this.$apollo.getClient("shopify")
                .mutate({
                    mutation: this.checkoutQuery,
                    variables: {
                        variantId: this.selectedProduct.variantId,
                        quantity: this.selectedProduct.quantity
                    }
                })
        }
}}

这不起作用,因为getClient()仅返回默认客户端(在这种情况下为WordPress)。 那么,如何通过一种方法访问其他客户端呢?

弄清楚了! 答案是这样的:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM