Retrieve content relationship document in one query

Hi I currently have using the js sdk to retrieve a document using its uid. I'd like to get the contents of a linked document ( content relationship field ) in that same query as the uid document call.

Example:
const doc = await api.getByUID("profile", "myuid");

The above brings me back all the fields in this document but I also want to get to all the document fields inside any linked fields in doc.

I'l like to do something like.
const doc = await api.getByUID("profile", "myuid", { fetchLinkedDocuments });

I have seen examples of fetching linked fields based on their name but I want to return all the fields without having to list them.
https://prismic.io/docs/technologies/fetch-linked-document-fields-reactjs

In the link above can I use the helper getByUID in combination with the options object example:
const doc = await api.getByUID("profile", "myuid", {fetchLinks: ['article.title', 'article.description']});
But instead of having to know all the fields upfront is there a way to fetch all the fields ?

Hello, welcome to the community!

An alternative to the fetchLinks parameter is[GraphQuery(API reference for GraphQuery (fetchLinks v2) - Prismic), a query option you can add to your Prismic queries to specify which fields to retrieve and what content to retrieve from Linked Documents / Content Relationships.

GraphQuery uses a GraphQL-like syntax and allows you to do selective fetching (i.e., fetch only the fields you need) and deep fetching (i.e., fetch the document + author in one request).

With this option, you will still need to specify each of the fields inside the linked documents but without the limitations of fetchLinks, which are not being able to query certain fields and any field in a Group or Slice. Plus, the GraphQL-like syntax makes the query more readable.

This issue has been closed due to inactivity. Flag to reopen.