简体   繁体   English

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

[英]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.

相关问题 Nuxt:如何在 fetch() 方法中访问 axios? - Nuxt: how do I access axios within the fetch() method? 我正在从 apollo-link-state 迁移到 @apollo/client,如何在不使用 cache.writeData 的情况下将默认数据写入 @apollo/client 的 InMemoryCache? - I am migrating from apollo-link-state to @apollo/client, how do I write default data to InMemoryCache of @apollo/client without using cache.writeData? 如何在本地Google App Engine的非默认模块上访问Google Cloud Endpoints? - How to access Google Cloud Endpoints on non-default module of local Google App Engine? 如何在tinymce编辑器中删除非默认wordpress编辑器的按钮 - How to remove buttons in tinymce editor for the non-default wordpress editor 如何使用Jest模拟非默认导入 - How to Mock non-default import using Jest 如何在Vanilla JS中使用Apollo Client创建GraphQL订阅 - How do I create a GraphQL subscription with Apollo Client in Vanilla JS 使用ui路由器导航到非默认状态 - Navigating to non-default state with ui router 在非默认浏览器中使用 Electron 打开 URL - Open URL with Electron in non-default Browser 如何在 Nuxt 的 asyncData 方法中获取用户的 IP? - How do I get the IP of a user in Nuxt's asyncData method? 骨干非默认根URL - Backbone non-default root url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM