首页 > 解决方案 > 无法在 Gatsby JS 上从 GraphQL 查询超链接

问题描述

我正在写一个关于 Gatsby JS 的博客,但我遇到了超链接问题,我无法解决它。

我有以下查询

const options = {
        renderNode: {
            "embedded-asset-block": (node) => {
                const alt = node.data.target.fields.title['es']
                const url = node.data.target.fields.file['es'].url
                return <img alt={alt} src={url} />
            },
            [INLINES.HYPERLINK]: (node) => {
                if(node.data.uri.indexOf('youtube.com') !== -1){
                    return(
                        <iframe width="560" height="315" src={node.data.uri} frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                    )
                }else{
                    return(
                    <a href={node.data.uri}>{node.content.value}</a>
                    )
                }
            }
        }
    }

通过这个查询,我可以添加资产和 youtube 视频。问题是,当我添加超链接时,它们会显示在页面上但没有文本。

我只看到<a href="https://www.test.es"></a>这个链接的而不是文本。

我知道问题出在这里<a href={node.data.uri}>{node.content.value}</a>,但我无法查询该值。

这是 GraphQL:

"body": {
              "json": {
                "nodeType": "document",
                "data": {},
                "content": [
                  {
                    "nodeType": "paragraph",
                    "content": [
                      {
                        "nodeType": "text",
                        "value": "Desde ",
                        "marks": [],
                        "data": {}
                      },
                      {
                        "nodeType": "hyperlink",
                        "content": [
                          {
                            "nodeType": "text",
                            "value": "FelixDigital",
                            "marks": [],
                            "data": {}
                          }

我需要查询值(FelixDigital)

有人可以帮助我吗?

太感谢了,

标签: reactjsgraphqlgatsby

解决方案


Can you do a debugger inside this code?

It's hard to say.. but what I would check is the value of node. To me it looks like content is an array and inside the first item of the array you have value so to me it should look more like node.content[0].value.


推荐阅读