1

我使用 gatsby 和 netlify-cms。我的架构:

collections:
  - name: "tags"
    label: "Tags"
    folder: "src/data/tags"
    create: true
    slug: "{{slug}}"
    fields: 
      - {label: "Id", name: "title", widget: "string"}
      - {label: "Description", name: "description", widget: "text"}
  - name: "posts"
    label: "Posts"
    folder: "src/data/posts"
    create: true
    slug: "{{slug}}"
    fields:
      - {label: "Id", name: "title", widget: "string"}
      - label: "Tags"
        name: "tags"
        widget: "list"
        fields:
          - label: "Tag"
            name: "tag"
            widget: "relation"
            collection: "tags"
            searchFields: ["name", "description"]
            valueField: "title"
            displayFields: ["name"]

我的查询:

query PostByID($id: String!) {
    markdownRemark(id: { eq: $id }) {
      id
      html
      frontmatter {
        id: title
        description
        tags {
            tag
            // get tag description????
        }
      }
    }
  }

有没有办法获取标签描述?我正在尝试使用片段,但它不起作用。我在 Gatsby GitHub 上提出了这个问题,有人建议我这个例子:

fragment tagDetails on Tag {
  title
  description
}

并使用此用法:

            tag {
              ...tagDetails
            }

我收到此错误:“字段 \"tag\" 不能有选择,因为类型 \"String\" 没有子字段。”

4

0 回答 0