api - 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>
- 这是正确的设置吗?
- 我似乎遇到了 cors 政策错误。我相信这与 Shopify 需要的缺少标题有关:https ://help.shopify.com/en/api/graphql-admin-api/getting-started#authentication
- 如何将“X-Shopify-Access-Token”添加到设置中?
任何帮助将非常感激。
谢谢
解决方案
这就是我们在 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/
推荐阅读
- python - 如何在python中使用for循环转换单位矩阵
- assembly - 在 MIPS 中使用 $0 加载值
- javascript - 复制数组并删除字符串?Javascript
- python - 如何在使用 groupby 时显示 pandas 数据框的行号?
- c++ - 有人可以告诉这段代码有什么问题吗,它会在执行时立即终止
- object-detection - 使用联邦学习进行对象检测
- c# - Blazor:计算多个文本框的总和
- android - 如何在媒体切换输出中显示媒体元数据信息?
- laravel - 卸载 torrix/laravel-uikit
- python - 将numpy转换为字符串时空格数不均匀