Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在gatsby中的graphql上查询实体_Reactjs_Gatsby_Contentful_Gatsby Plugin - Fatal编程技术网

Reactjs 如何在gatsby中的graphql上查询实体

Reactjs 如何在gatsby中的graphql上查询实体,reactjs,gatsby,contentful,gatsby-plugin,Reactjs,Gatsby,Contentful,Gatsby Plugin,我正试图使用2019年的教程创建一个博客,该教程使用了内容插件,但我看到gastby更新了他们的文档,所以我无法完成视频中看到的内容,我的问题是,我不太理解下面的文档 当我开始使用http://localhost:8000/___graphql 在那之前 query { allContentfulBlogPost ( filter: {node_locale: {eq: "en-US"}} sort: { fields: publishedD

我正试图使用2019年的教程创建一个博客,该教程使用了
内容插件
,但我看到gastby更新了他们的文档,所以我无法完成视频中看到的内容,我的问题是,我不太理解下面的文档

当我开始使用
http://localhost:8000/___graphql
在那之前


query {
  allContentfulBlogPost (
    filter: {node_locale: {eq: "en-US"}}
    sort: {
      fields: publishedDate,
      order: DESC
    }
  ) {
    edges {
      node {
        title node_locale
        slug
        publishedDate(formatString: "MMMM Do, YYYY")
        body {
          json
        }
          
          
        
        
      }
    }
  }
}
现在我看到了内容丰富的文档
注意:请注意,盖茨比内容源插件的早期版本使用了json字段。此选项已被raw替换,以便在渲染时提供更大的灵活性并解决性能问题。

query {
  allContentfulBlogPost {
    edges {
      node {
        bodyRichText {
          raw
          references {
            ... on ContentfulAsset {
              contentful_id
              fixed(width: 1600) {
                width
                height
                src
                srcSet
              }
            }
            ... on ContentfulBlogPost {
              contentful_id
              title
              slug
            }
          }
        }
      }
    }
  }
}
在graphql上,我没有这个
bodyRichText
,我只有
body{raw}
,但使用这个类似于:

export const query = graphql`
    query($slug: String!) {
        contentfulBlogPost(slug: {eq: $slug}) {
            title
            publishedDate(formatString: "MMMM Do, YYYY")
            body {
                raw
            }
        }


    }


`

const Blog = (props) => {
    return (
        <Layout>
            <h1>{props.data.contentfulBlogPost.title}</h1>
            <p>{props.data.contentfulBlogPost.publishedDate}</p>
            {documentToReactComponents(props.data.contentfulBlogPost.body.raw)}
        </Layout>
    )
}

export default Blog
export const query=graphql`
查询($slug:String!){
contentfulBlogPost(slug:{eq:$slug}){
标题
publishedDate(格式字符串:“MMMM Do,YYYY”)
身体{
未经加工的
}
}
}
`
康斯特博客=(道具)=>{
返回(
{props.data.contentfulBlogPost.title}
{props.data.contentfulBlogPost.publishedDate}

{documentToReactComponents(props.data.contentfulBlogPost.body.raw)} ) } 导出默认博客

不起作用,所以我遗漏了一些东西,但我无法找到它是什么。

正如您所说,
body
现在被弃用,取而代之的是
raw
,以便我们在从Contentful进行采购时,在创建自定义输出时具有更大的灵活性

这个想法,给出了一个如下的问题:

query {
  allContentfulBlogPost {
    edges {
      node {
        bodyRichText {
          raw
          references {
            ... on ContentfulAsset {
              contentful_id
              fixed(width: 1600) {
                width
                height
                src
                srcSet
              }
            }
            ... on ContentfulBlogPost {
              contentful_id
              title
              slug
            }
          }
        }
      }
    }
  }
}
如果您没有
bodyRichText
节点,请在
localhost:8000/\uuuuuu graphql
上检查它们的可用性。输出应该完全相同

在获得响应对象和引用后,idea将使用支持的Contentful:

) }, }, } ​ renderRichText(node.bodyRichText,选项) 使用这些连接器的目的是定制输出。使用:

<div dangerouslySetInnerHTML={{__html: props.data.contentfulBlogPost.body.raw}} />;
永远不会产生预期的产出。也许你正在寻找:


因为它是原始内容。

你能澄清一下“什么不起作用”吗?输出是什么,日志,等等,我不知道我给你的回复是否放在正确的地方。我编辑了你的答案,因为Stackoverflow不允许用大文本进行评论-对不起,我是新来的,用这样的方式使用它:这里有一个例子。这里也是:
{documentToReactComponents(props.data.contentfulBlogPost.body.raw)}
<div dangerouslySetInnerHTML={{__html: props.data.contentfulBlogPost.body.raw}} />;