在我的 gatsby graphql 中,woocommerce 购物车总是空着
The woocommerce cart always comes up empty in my gatsby graphql
这是我的第一个问题,希望我做对了。我正在尝试为我的 woocommerce 制作一个 gatsby 前端,一切正常。直到现在我所有的查询都工作得很好,但是当我查询以获取购物车信息时,它在我的本地主机上总是空的://8000/___graphql 但在 wp graphiql 中我可以看到它就好了。
这是我的 gatsby-config 我想这就是问题所在。
siteMetadata: {
title: "shopone",
},
plugins: [
{
resolve: `gatsby-source-wordpress`,
options: {
url:
process.env.WPGRAPHQL_URL ||
`https://wpurl/graphql`,
},
},
{
resolve: "gatsby-source-graphql",
options: {
typeName: "WPGraphQL",
fieldName: "wpcontent",
url: "https://wpurl/graphql",
},
},
{
resolve: 'gatsby-wpgraphql-inline-images',
options: {
wordPressUrl: 'https://my/wpurl/',
uploadsUrl: 'https://my/url/wp-content/uploads/',
processPostTypes: ['Page', 'Post', 'CustomPost'],
graphqlTypeName: 'WPGraphQL',
httpHeaders: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
}
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: (__dirname, `src`),
},
},
`gatsby-plugin-sass`,
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`
],
};
这是因为您的 localhost:8000/___graphql
是在构建时生成的,此时,购物车将始终是空的,因为尚未允许用户填充它。
您的 WP GraphiQL API 是一个异步的 API 实时获取数据,当用户填充购物车时按需获取数据,因此它总是包含请求完成。要“连接”两者,您需要对 API.
执行一些 fetch/post 请求
您可以在 Build Time and Client Runtime Data Fetching 中阅读更多信息。
这是我的第一个问题,希望我做对了。我正在尝试为我的 woocommerce 制作一个 gatsby 前端,一切正常。直到现在我所有的查询都工作得很好,但是当我查询以获取购物车信息时,它在我的本地主机上总是空的://8000/___graphql 但在 wp graphiql 中我可以看到它就好了。
这是我的 gatsby-config 我想这就是问题所在。
siteMetadata: {
title: "shopone",
},
plugins: [
{
resolve: `gatsby-source-wordpress`,
options: {
url:
process.env.WPGRAPHQL_URL ||
`https://wpurl/graphql`,
},
},
{
resolve: "gatsby-source-graphql",
options: {
typeName: "WPGraphQL",
fieldName: "wpcontent",
url: "https://wpurl/graphql",
},
},
{
resolve: 'gatsby-wpgraphql-inline-images',
options: {
wordPressUrl: 'https://my/wpurl/',
uploadsUrl: 'https://my/url/wp-content/uploads/',
processPostTypes: ['Page', 'Post', 'CustomPost'],
graphqlTypeName: 'WPGraphQL',
httpHeaders: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
}
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: (__dirname, `src`),
},
},
`gatsby-plugin-sass`,
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`
],
};
这是因为您的 localhost:8000/___graphql
是在构建时生成的,此时,购物车将始终是空的,因为尚未允许用户填充它。
您的 WP GraphiQL API 是一个异步的 API 实时获取数据,当用户填充购物车时按需获取数据,因此它总是包含请求完成。要“连接”两者,您需要对 API.
执行一些 fetch/post 请求您可以在 Build Time and Client Runtime Data Fetching 中阅读更多信息。