Query linked document data inside a group field

I’m trying to run this query:

const page = await $prismic.api.query([
  $prismic.predicates.at('document.type', 'homepage'),
  $prismic.predicates.at('my.homepage.main_projects.project', homeId),

In the homepage, I have a group field (main_projects)
Within the group field, I have a relationship field (API ID: main_project) linking to a custom type (API Id: project)

I’m trying to get data of the custom type document that is added with the relationship field in the group field.

However, the query does not return any results.

If I run this:

const page = await $prismic.api.query([
  $prismic.predicates.at('document.type', 'homepage'),

It returns the homepage data but I don’t seem to get the data of the custom type added in the relationship in the group

Any ideas?

Thank you!

Hello @fransy, your first query seems correct, but you also have to use FetchLinks to retrieve Document Fields from those linked documents.

Hello Paulina,
Yes, FetchLinks worked.
Thank you!

WOAH! You can get linked items in a group?

Are the docs wrong? I had thought it was “not possible to retrieve…Any field in a Group or Slice

Hi @rjessome,

I think maybe the docs are a bit confusing in that regard.

not possible to retrieve…Any field in a Group or Slice

This means that with FetchLinks you cannot get the content of a group field inside the linked document, for that you would need to use GraphQuery.

What Paulina and Fransy are talking about is querying data from multiple linked documents where the links live in a group field in the main document.

OH! I see.

Yeah - I totally read it differently! Thanks for clarifying, though!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.