GraphQuery not fetching data of content-relationship in repeatable zone

Hi,

I have a homepage type with a slice (named: links). The repeatable zone of the slice has a content relationship which accepts 1 type (named: link). The link type has just a basic title, image and rich text.
I retrieve the data using following graphquery:

{
    homepage {
      body {
        ...on links { //SLICE
          non-repeat {
            ...non-repeatFields
          }
          repeat {
            ...repeatFields
          }
        }
    }
}

I'm fetching data with:

  const result1 = await client.getSingle('homepage', { graphQuery: myGraphQuery }).then(function (document) {
    return document;
  });

In my response i'm receiving the basic information of the link type, but not the necessary data. The response looks something like this:

data {
    body {
        links {
            items [
                 {
                     id: xxx
                     lang: xxx
                     ....
                     ....
                     ! MISSING DATA ATTRIBUTE
                 },
                 ...
            ]
        }
    }
}

How can I get all this missing information on my relation-item without having to perform extra api calls (waterfall style)?

Hi @kevin.vannimmen, the Content Relationship field won’t provide any content from the linked document unless you specify in your GraphQuery what you are looking for. Here is the documentation for this.

I believe that your GraphQuery needs to look something like this:

{
  homepage {
    body {
      ...on links { //SLICE
        non-repeat {
          ...non-repeatFields
        }
        repeat {
          ...repeatFields
          name_of_content_relationship_field {
            ... on linked_doc_type {
              ...linked_doc_type_Fields
            }
          }
        }
      }
  }
}

Give that a try (updating the names that need to be updated of course) and let me know if it works for you.

Thank you for the help!

I adapted my query like you said above and it works, but I think there is a bug here as-well. I cannot get the data if the linked_doc_type is named “link”. Which here is the case. If I created a new custom type and named it “link-item” instead of “link” it works.

Thanks for letting us know about this. I will inform the dev team about this so hopefully they can address it soon.

Hi! I'm having a similar issue where I have a Custom Type of type Single named featured_categories that has a repeatable group of linked documents of type category. This is my query using graphQuery

const exclusive = await client.getSingle("featured_categories", {
  graphQuery: `{
    categories {
      category {
        ...on category {
          ...categoryFields
        }
      }
    }
  }`,
})

This does not error out but it doesn't return any data from the category documents.
If instead I use fetchLinks like this

const exclusive = await client.getSingle("featured_categories", {
  fetchLinks: [
    "category.uid",
    "category.title",
  ],
})

this works fine, I get back the uid and the title as part of the data from the category linked document

Any ideas why?

Thanks!

Hello @levijesica

Thanks for reaching out to us. You should mention the name of the Custom Type in your graphQuery. It should look like this:

const mySuperGraphQuery = `{
    featured_categories {
        categories {
            category {
                ...on category {
                    ... categoryFields
                }
            }
        }
    }
}`
const exclusive = await client.getSingle("featured_categories", {
 { 'graphQuery': mySuperGraphQuery }
}

Give this a try and let me know.

Thanks,
Priyanka

1 Like