Hi,
currently I'm testing to fetch data on the server side with Next.JS and the following code:
export async function getServerSideProps({ query }) {
const client = Client();
const report = await client.getByUID("report", query.slug, { lang: "de-de" });
return {
props: {
report
}
};
}
In the content model I've also integrated a repeater field with a content relationship. Now I want to query also the content of the documents from the content relationship field.
How can I do this?
Hey Marco!
Thanks for posting this question. There are a few ways to do this:
You could you GraphQuery (which has a similar syntax to GraphQL) to fetch content from linked documents
You could add a forEach
loop after your first query to iterate over the repeater field and query each document
Or — and this is what I recommend — you can add a fetchLinks
option to your query to fetch the content that you need
If you'd like to use fetchLinks, there are some instructions here:
Hey @rizqinizamil ,
Welcome to the Prismic community, and thanks for posting this question!
To fetch content relationships, you can use the fetchLinks option:
To use fetchLinks, add an options object to your query, with a fetchLinks key. For the fetchLinks key, set the value to [custom-type-of-linked-document].[field-on-linked-document].
When you include the fetchLinks option, the API will fetch the field on every linked custom type in your document, incl…
Let me know if you have any questions about fetchLinks. And, otherwise, If you'd like more info on GraphQuery or using a foreach loop, let me know
Best,
Sam
Hi @samlittlefair ,
I already tried to use the fetchLinks
option, but did it wrong. Now it's working.
Thanks for your help!
system
(system)
closed as resolved, flag & select 'Something Else' to reopen.
January 7, 2021, 2:28pm
5
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.