首页 > 解决方案 > Nuxt 阿波罗 Shopify Graphql

问题描述

所以我正在使用https://github.com/nuxt-community/apollo-module 我正在尝试将其设置为连接到我的 shopify graphql API

在 nuxt.config.js 上:

  apollo: {
    clientConfigs: {
      default: {
        httpEndpoint: 'https://my-store.myshopify.com/admin/api/2020-01/graphql.json',
        getAuth: () => 'Bearer 26cfd63bbba75243b55fad2c8de0a12f'
      },
    }
  },

在 index.vue 上,我有以下内容:

  <script>
    import gql from 'graphql-tag'

    export default {
      apollo: {
        data: {
          query: gql`
            query {
              shop {
                name
              }
            }
          `,
        }
      }
    }
  </script>

任何帮助将非常感激。

谢谢

标签: apigraphqlshopifyapollonuxt.js

解决方案


这就是我们在 Nuxt Config 中的工作方式。

    apollo: {
        clientConfigs: {
            default: {
                httpEndpoint:
                    "http://api.another-backend-example.com/graphql",
                persisting: false
            },
            shopify: {
                httpEndpoint:
                    "https://my-store.myshopify.com/api/2019-07/graphql.json",
                httpLinkOptions: {
                    headers: {
                        "Content-Type": "application/json",
                        "X-Shopify-Storefront-Access-Token":
                            "123456789abcdefghi"
                    }
                },
                persisting: false
            }
        }
    }

我们还为 Nuxt 构建了很多有用的 Shopify 组件,也许这对您有帮助:https ://github.com/funkhaus/shophaus/


推荐阅读