英文:
Nuxt Apollo Shopify Graphql
问题
Here's the translated content:
我正在使用 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>
- 这是正确的设置吗?
- 我似乎收到了跨域策略错误。我认为这与 Shopify 要求的缺少标头有关: https://help.shopify.com/en/api/graphql-admin-api/getting-started#authentication
- 如何将 'X-Shopify-Access-Token' 添加到设置中?
任何帮助将不胜感激。
谢谢
英文:
So I am using the https://github.com/nuxt-community/apollo-module
I am trying to set this up to connect to my shopify graphql API
On nuxt.config.js:
apollo: {
clientConfigs: {
default: {
httpEndpoint: 'https://my-store.myshopify.com/admin/api/2020-01/graphql.json',
getAuth: () => 'Bearer 26cfd63bbba75243b55fad2c8de0a12f'
},
}
},
on index.vue, i have the following:
<script>
import gql from 'graphql-tag'
export default {
apollo: {
data: {
query: gql`
query {
shop {
name
}
}
`,
}
}
}
</script>
- is this the correct set up?
- I appear to be getting a cors policy error. I believe this is to do with missing headers that Shopify requires: https://help.shopify.com/en/api/graphql-admin-api/getting-started#authentication
- how do I add 'X-Shopify-Access-Token' to the setup?
Any help would be much appreciated.
Thanks
答案1
得分: 2
这是我们在Nuxt配置中的工作方式。
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/
英文:
This is how we have it working in our 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
}
}
}
We also built a lot of useful Shopify components for Nuxt, maybe this helps you: https://github.com/funkhaus/shophaus/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论