Gatsby 盖茨比公司;内容查询

Gatsby 盖茨比公司;内容查询,gatsby,contentful,Gatsby,Contentful,我很难找到准确描述如何使用“gatsby source contentful”插件和从contentful API查询数据的文档。我在gatsby-config.js文件中设置了所有内容,没有运行错误。我想知道如何开始打这些电话。我已经查看了/\uuuuuu图形ql路径,没有看到任何与contentful相关的查询选项 如有任何信息,将不胜感激 这是我的插件配置数据 { resolve: `gatsby-source-contentful`, options: { spac

我很难找到准确描述如何使用“gatsby source contentful”插件和从contentful API查询数据的文档。我在gatsby-config.js文件中设置了所有内容,没有运行错误。我想知道如何开始打这些电话。我已经查看了/\uuuuuu图形ql路径,没有看到任何与contentful相关的查询选项

如有任何信息,将不胜感激

这是我的插件配置数据

{
   resolve: `gatsby-source-contentful`,
   options: {
     spaceId: keys.spaceId,
     accessToken: keys.accessToken,
   },
},

您的gatsby配置文件似乎正常(如果您的accessToken有效,则不会出现错误)。尝试以下示例查询以从Contentful检索数据:

export const pageQuery = graphql`
  query HomeQuery {
    allContentfulBlogPost(sort: { fields: [publishDate], order: DESC }) {
      edges {
        node {
          title
          slug
          publishDate(formatString: "MMMM Do, YYYY")
          tags
          heroImage {
            sizes(maxWidth: 350, maxHeight: 196, resizingBehavior: SCALE) {
             ...GatsbyContentfulSizes_tracedSVG
            }
          }
          description {
            childMarkdownRemark {
              html
            }
          }
        }
      }
    }
    allContentfulPerson(filter: { id: { eq: "c15jwOBqpxqSAOy2eOO4S0m" } }) {
      edges {
        node {
          name
          shortBio {
            shortBio
          }
          title
          heroImage: image {
            sizes(
              maxWidth: 1180
              maxHeight: 480
              resizingBehavior: PAD
              background: "rgb:000000"
            ) {
              ...GatsbyContentfulSizes_tracedSVG
            }
          }
        }
      }
    }
  }
`
在页面内,您可以通过以下方式访问数据:

const siteTitle = this.props.data.site.siteMetadata.title;
const posts = this.props.data.allContentfulBlogPost.edges;
const [author] = this.props.data.allContentfulPerson.edges;

我在type
Query
@JoshBowden上获得错误图ql error Unknown field
allContentfulBlogPost
,创建此查询后,需要重新启动gatsby(只有热重新加载不起作用)。您需要重新启动盖茨比开发过程。你这样做了吗?通过一些挖掘,我得到了一个错误,“GraphQL不适用于我的帐户”。这是否意味着contentful的免费层不允许我使用graphQL访问数据?@JoshBowden您在这一层做得怎么样?您可以将GQL与contentful的免费层一起使用。我有超过15个内容模型和大量的内容,非常适合查询。正如上面提到的,您必须重新启动开发服务器,但我认为您还必须刷新缓存。因此,我总是运行(从项目的根开始)的是
gatsby clean&&warn start
。如果有人对如何做得更好有任何意见,请分享。