Contentful logo

Contentful Community

How do I query a content type of "References, many"?

I have a content type “Collection”, with a field “contentSections” (a “References, many” field). I need to display the referenced content in the same order. The query $page.collection.contentSections.content is empty.

  • contentSections
    – Referenced content 1
    – Referenced content 2
    – Referenced content 3

$page.collection.contentSections.content is not valid in REST API, you could query the main entry with include parameter: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links/retrieval-of-linked-items, the linked entries will be in the same order of web app in the API response.

Hello Alma, thank you for your response! Sorry, I should have mentioned that I am using GraphQL.

Are the referenced entries also published?

Yes, they are published. I do see the content in the GraphQL playground, but when I copy the query and put that in my Gridsome template the reference is empty.

@charlie, the referenced entries are published. I am attaching a screenshot of my query and as you can see the content for both referenced sections can be queried. But when I reference this content in Gridsome using the path $page.page.sections.content, the content is empty. Is $page.page.sections.content incorrect?

Figured it out. Need to loop through the array of references.
v-for=“reference in edge.node.references” :key=“reference.id”
v-html=“richTextToHTML(reference.richText)”