微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

graphql 在本地工作但不在 Netlify (Gatsby + Netlify CMS)

如何解决graphql 在本地工作但不在 Netlify (Gatsby + Netlify CMS)

我正在尝试将 Markdown 文件注入到我的 Gatsby 页面中,该页面在本地运行(开发和服务器)。但是,同样的 graphql 查询在 Netlify 中无法返回数据。对我来说似乎很奇怪。

这是一个示例 graphql 查询

export const query = graphql`
  query {products_horizontal: file(
      sourceInstanceName: { eq: "products" }
      childMarkdownRemark: { frontmatter: { vertical: { eq: false } } }
    ) {
      sourceInstanceName
      childMarkdownRemark {
        frontmatter {
          title
          date
          store
          vertical
          price
          image
          templateKey
          description
          featuredpost
          featuredimage
          tag
          color
        }
      }
    }}`

我在构建时添加一个 console.log 来查看我的数据对象的内容,下面是我的应用程序的本地构建

  products_horizontal: {
    sourceInstanceName: 'products',childMarkdownRemark: { frontmatter: [Object] }
  },

如您所见,product_horizo​​ntal 有一个备注节点。现在,当涉及到 netlify 中完全相同的文件时。我得到以下信息:

products_horizontal: null

注意:当我从过滤器中删除 frontmatter: { vertical: { eq: false } } 时,它也适用于 Netlify。

我已经被这个错误困扰了大约 6 个小时,非常感谢您的帮助。我现在将添加更多代码以供参考。 gatsby-config.js

module.exports = {
  plugins: [
    `gatsby-plugin-sass`,`gatsby-plugin-sharp`,"gatsby-plugin-netlify-cms",`gatsby-transformer-sharp`,{
      resolve: `gatsby-transformer-remark`,options: {
        // commonmark mode (default: true)
        commonmark: true,// Footnotes mode (default: true)
        footnotes: true,// Pedantic mode (default: true)
        pedantic: true,// GitHub Flavored Markdown mode (default: true)
        gfm: true,// Plugins configs
        plugins: [],},{
      resolve: `gatsby-source-filesystem`,options: {
        name: "images",path: `${__dirname}/src/images`,options: {
        name: "products",path: `${__dirname}/product`,options: {
        name: "blogs",path: `${__dirname}/blog`,options: {
        name: "tags",path: `${__dirname}/tag`,{
      resolve: "gatsby-plugin-layout",options: {
        component: require.resolve(`./src/components/Layout/index.tsx`),{
      resolve: `gatsby-plugin-intl`,options: {
        path: `${__dirname}/src/intl`,languages: [`en`,`az`,`ru`],defaultLanguage: `en`,redirect: false,],}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。