首页 > 解决方案 > 添加从内容和 gatsby 生成的可点击标签

问题描述

非常关注这篇文章将标签添加到 Gatsby Contentful 博客到 T 但仍然找不到它不起作用的原因......

import React from "react"
import { graphql } from "gatsby"

export const query = graphql`
  query($slug: String!, $tag: [String!]) {
    contentfulBrunchPost(slug: { eq: $slug }, tag: { in: $tag }) {
      title
      slug
      tag
    }
  }
`

const TagPost = props => {
  return <h1>{props.data.contentfulBrunchPost.title}</h1>
}

export default TagPost

我收到错误“无法读取未定义的属性‘contentfulBrunchPost’”。graphiQL 在内容和 gatsby 方面非常新,所以指出正确的方向会很棒

标签: reactjsgatsbycontentfulgraphiql

解决方案


我建议去你的本地版本的 Graphiqlhttp://localhost:8000/___graphql并复制你的确切查询。查询是否在那边返回数据?如果不是,那么您的查询可能不正确。如果它确实返回数据,那么您可以深入研究它以确定要在代码中使用的正确引用。


推荐阅读