【问题标题】:Gatsby: gatsby-source-graphql & gatsby-plugin-sharp in graphql queryGatsby:graphql 查询中的 gatsby-source-graphql 和 gatsby-plugin-sharp
【发布时间】:2019-04-02 14:44:57
【问题描述】:

我正在使用 Gatsby v. 2.0.2。作为一个无头 CMS,我正在使用 Strapi。我正在尝试对从 Strapi 上传的图片使用 gatsby-image、gatsby-plugin-sharp(图像处理)。

我的文件夹结构是:

>>projectfolder
   >>api
     >>public
       >>uploads (here my images are located)
   >>frontend (gatsby stuff)

类似于 Gatsby-source-wordpress 我想像这样用graphql查询图像:

query {
  api {
    projects {
      image {
        name
        url
        childImageSharp {
          resize(width: 180, height: 180) {
            src
          }
        }
      }
    }
  }
}

如果我使用exports.onCreateNode,我只会得到父节点“api”。如何获取图片 URL 以便使用 createRemoteFileNode?​​p>

是否需要编写exports.createPages,graphql查询api-node然后使用createNode或createNodeField创建节点?


我尝试使用 Gatsby-source-strapi 时遇到同样的问题,无法访问 Gatsby-transformer-sharp。

query {
  allStrapiProject {
    edges {
      node {
        title
        image {
          name
        }
      }
    }
  }
}

【问题讨论】:

    标签: graphql gatsby strapi


    【解决方案1】:

    这是在最近的拉取请求中添加的,并将在接下来的几天内发布在 npm 上:https://github.com/strapi/gatsby-source-strapi/pull/24。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-05
      • 2019-10-26
      • 2020-11-14
      • 2020-08-11
      • 2020-03-14
      • 2020-03-23
      • 1970-01-01
      • 2019-09-29
      相关资源
      最近更新 更多