【问题标题】:contentful graphql nested structure内容丰富的graphql嵌套结构
【发布时间】:2021-07-17 18:09:29
【问题描述】:

我有一个内容丰富的页面,我使用 graphql 将内容检索到我的反应应用程序。 在这个页面中,一个名为 Person 的内容模型的链接是这样的:

{
  "name": "Person",
  "description": "",
  "displayField": "name",
  "fields": [
    {
      "id": "name",
      "name": "Name",
      "type": "Symbol",
      "localized": false,
      "required": true,
      "validations": [],
      "disabled": false,
      "omitted": false
    },
    {
      "id": "profilePic",
      "name": "profile pic",
      "type": "Link",
      "localized": false,
      "required": true,
      "validations": [],
      "disabled": false,
      "omitted": false,
      "linkType": "Asset"
    },
    {
      "id": "socialLinks",
      "name": "social links",
      "type": "Array",
      "localized": false,
      "required": false,
      "validations": [],
      "disabled": false,
      "omitted": false,
      "items": {
        "type": "Link",
        "validations": [
          {
            "linkContentType": [
              "socialLink"
            ]
          }
        ],
        "linkType": "Entry"
      }
    }

ProfilePic 是另一种包含名称和图片网址的内容模型。 SocialLinks 是一个包含名称和链接的socialLink 内容模型数组

我可以毫无问题地检索我的 profilePic 名称或 picUrl,但我无法获取 socialLinks。 我已阅读有关一对多的内容丰富的文档,但我不清楚如何申请我的案例:https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/one-to-many-multi-type-relationships

我的查询:

...rest of the query..
      founder{
        name,
        profilePic{
          url,
          title
        },
        socialLinksCollection {
          items {
            name,
            link
          }
        }
      },
... rest of the query...

somoene 能帮我理解为什么它不能作为一个普通的收藏吗? 我应该使用linkedFrom这个概念吗?但具体如何?

【问题讨论】:

标签: graphql contentful contentful-api


【解决方案1】:

我不得不在我的 socialLinksCollections 中添加(限制:1),否则调用太多,无法取回数据。 感谢@stefan judis 提出的在哪里寻找错误的建议。

【讨论】:

    猜你喜欢
    • 2021-07-15
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    • 2016-08-25
    相关资源
    最近更新 更多