Markdown 节点和 TMDB 节点之间的 Gatsby 映射不再起作用

发布于 2025-01-11 05:05:25 字数 425 浏览 0 评论 0 原文

我刚刚将一个项目从 V2 升级到 V4.8,Gatsby 配置中的一个简单映射似乎不再起作用。正在创建节点,但任何查询都只是在链接字段上返回“null”。这是我在 gatsby-config.js 中的映射:

 mapping: {
    'MarkdownRemark.frontmatter.tmdb': `TmdbAccountWatchlistMovies.tmdbId`
  },

该关系看起来像是在 graphql 中创建的: 显示链接的查询

但是,查询仅对任何链接字段返回 null: 在此处输入图像描述

有人知道发生了什么吗?

I have just upgraded a project from V2 to V4.8 and a simple mapping that I have in my Gatsby-config doesn't seem to be working anymore. The nodes are being created but any queries are just returning 'null' on the linked field. Here's my mapping in gatsby-config.js:

 mapping: {
    'MarkdownRemark.frontmatter.tmdb': `TmdbAccountWatchlistMovies.tmdbId`
  },

The relationship looks like it is being created in graphql:
query showing linkage

But, the query just returns null for any of the linked fields:
enter image description here

Anyone have any idea what is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡Ms空城旧梦 2025-01-18 05:05:25

嗯,我应该在哪里包含该指令?

它应该放置在 gatsby-node.js 内rel="nofollow noreferrer">createSchemaCustomization API

@link 的指令是自定义 GraphQL 架构的首选方式,而不是直接将节点映射到 gatsby-config.js 内。它增加了额外的安全性和可靠的定制层,但当然它也增加了额外的难度。

在类型声明之前,需要设置外键字段的关系。如果不深入研究您的数据结构,我无法知道代码应该是什么样子,但它可能类似于:

exports.createSchemaCustomization = ({ actions }) => {
  { createTypes } = actions
  const typeDefs = `
    type MarkdownRemark implements Node {   
      frontmatter: Frontmatter 
    }  
    type Frontmatter {   
      tmdb: [tmdbAccountWatchlistMovies] @link(by: "tmdbId") 
    }
  `
  createTypes(typeDefs)
}

仔细检查 tmdbAccountWatchlistMovies 以查看节点是否按原样可用或现在可用以某种方式嵌套。

Hmm where would I include that directive?

It should be placed inside the gatsby-node.js inside the createSchemaCustomization API.

@link's directive is the preferred way of customizing the GraphQL schema, rather than directly mapping your node inside the gatsby-config.js. It adds an extra security and solid customization layer but of course it also adds an extra difficulty.

Before the type declaration, you need to set the relation of the foreign-key field. Without digging more into your data structure I'm not able to know how the code should look like but it may be something like:

exports.createSchemaCustomization = ({ actions }) => {
  { createTypes } = actions
  const typeDefs = `
    type MarkdownRemark implements Node {   
      frontmatter: Frontmatter 
    }  
    type Frontmatter {   
      tmdb: [tmdbAccountWatchlistMovies] @link(by: "tmdbId") 
    }
  `
  createTypes(typeDefs)
}

Double-check the tmdbAccountWatchlistMovies to see if the node is available as is or is nested somehow.

椵侞 2025-01-18 05:05:25

找到了——哦。这些值已从 Int 类型更改为 String 类型,因此只需将 ID 用撇号括起来即可。

Found it--doh. The values had changed from Int to String types so just needed to wrap the IDs in apostrophes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文