contentful graphql nested structure

892 views Asked by At

I have a page in contentful which I retrieve content to my react app with graphql. In this page, a link a content model called Person which is like that:

{
  "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 is another content model which include name and picUrl. SocialLinks is an array of socialLink content model which contain name and link

I can retrieve without problem my profilePic name or picUrl but I cannot get the socialLinks. I have read the contentful documentation about one-to-many but is not clear to me how to apply to my case: https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/one-to-many-multi-type-relationships

My query:

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

Can somoene help me understand why it doesn't work as a normal collection? Should I maybe use this concept of linkedFrom? But how exactly?

1

There are 1 answers

0
Giorgia Sambrotta On BEST ANSWER

I had to add (limit: 1) to my socialLinksCollections otehrwise there were too many calls and wasn't possible to get the data back. Thanks to @stefan judis for the suggestion where to look out for the errors.