Javascript 如何向Gatsby sourceNode添加JSON字段?

Javascript 如何向Gatsby sourceNode添加JSON字段?,javascript,json,graphql,gatsby,Javascript,Json,Graphql,Gatsby,在我的API中,我有带有动态模式的layoutprop,因此我将其作为字符串化JSON添加到sourceNode: for (const { path } of nodesList) { /* ... */ const node = { id: createNodeId(`cms-${cmsNode.id}`), /* this prop */ layout: JSON.stringify(layout), parent: n

在我的API中,我有带有动态模式的
layout
prop,因此我将其作为字符串化JSON添加到
sourceNode

  for (const { path } of nodesList) {
    /* ... */

    const node = {
      id: createNodeId(`cms-${cmsNode.id}`),
      /* this prop */
      layout: JSON.stringify(layout),
      parent: null,
      children: [],
      internal: {
        content: JSON.stringify(cmsNode),
        type: 'CmsNode',
      },
    }
    node.internal.contentDigest = createContentDigest(node)
    createNode(node)
  }

如何自定义此字段以在查询级别解析JSON,而不是在页面组件中解析JSON。我应该添加自定义类型:

exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  const typeDefs = `
    type CmsNode implements Node @dontInfer {
      id: ID!
      parent: Node
      children: [Node!]!
      ...
      layout: JSON
    }
  `
  createTypes(typeDefs)
}

不要在
createNode

期间将此道具字符串化,我应该添加自定义类型:

exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  const typeDefs = `
    type CmsNode implements Node @dontInfer {
      id: ID!
      parent: Node
      children: [Node!]!
      ...
      layout: JSON
    }
  `
  createTypes(typeDefs)
}
createNode

使用graphql自定义json类型(文档)期间,不要将此道具字符串化。。。不要将graphql自定义json类型(文档)字符串化。。。不要把它串起来