graphql - Gatsby GraphQL 无法在 Strapi 的类型 "url"上查询字段 "File"

标签 graphql gatsby strapi

我正在用 Gatsby 前端和 Strapi 后端制作博客。我使用 StaticQuery 在组件中进行了查询

query={graphql`
        query {
          allStrapiArticle {
            edges {
              node {
                strapiId
                title
                category {
                  name
                }
                image {
                  url
                }
              }
            }
          }
        }
      `}
在没有 image{url} 的情况下,所有领域都可以正常工作.我收到错误:error Cannot query field "url" on type "File" graphql/template-strings .我该如何解决?谢谢!

最佳答案

我也遇到过这个问题。关于 Strapi 的教程建议用'url'查询,但这是错误的。
正确的查询方法是:

      allStrapiArticle {
        edges {
          node {
            strapiId
            title
            category {
              name
            }
            image {
              publicURL
            }
          }
        }
      }
为了显示图像,不要忘记交换网址 进入 publicURL 像那样:
  <img
    src={article.node.image.publicURL}
    alt={article.node.image.publicURL}
    height="100"
  />

关于graphql - Gatsby GraphQL 无法在 Strapi 的类型 "url"上查询字段 "File",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62806312/

相关文章:

reactjs - 如何在没有 Gatsby 云的情况下使用 Gatsby 功能中的增量构建

websocket - 为变形过滤器重用已移动的变量

python - Graphite 烯的缺陷。突变?

Delphi 带有 Graph.cool API?

webpack - 如何在 GatsbyJS 中使用全局 CSS 样式表

reactjs - Gatsby (Gatsby)和斯特拉皮(Strapi)实现国际化的最佳途径

python - 压缩 GraphQL 查询?

gatsby - 带有 MarkdownRemark 的多种帖子类型

Strapi v4 - 上传到 S3 的图像不显示在媒体库中

javascript - Strapi v4 抛出 cors 异常