【问题标题】:Nuxt Apollo Shopify GraphqlNuxt Apollo Shopify Graphql
【发布时间】:2020-04-22 05:27:46
【问题描述】:

所以我使用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>

任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 我的回答有帮助吗?有什么遗漏的吗?

标签: api graphql shopify apollo nuxt.js


【解决方案1】:

这就是我们在 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/

【讨论】:

  • 谢谢!这帮助很大。我还查看了您的 git repo。这将对我网站的其他部分有所帮助。谢谢。
猜你喜欢
  • 2021-12-10
  • 2021-04-19
  • 2020-10-23
  • 2021-07-18
  • 2021-09-13
  • 2020-02-08
  • 2018-03-20
  • 2020-07-27
  • 1970-01-01
相关资源
最近更新 更多