Hey everyone, chiming in here to address one of the questions that came up.
When using Prismic with Gatsby, you can query for data infinitely deep as long as your query contains the fields. For example, if you had a Page document that references another Page document, which also references another Page document, you can query the relation fields the whole way down as needed.
In Rich Text fields, however, you are unable to query like you can in GraphQL. Instead, you must tell the Prismic API the extra relation field data to include.
This is done by providing a fetchLinks
value to gatsby-source-prismic
's plugin options in your project's gatsby-config.js
file.
You can read more about Prismic's fetchLinks
option here: https://prismic.io/docs/technologies/fetch-linked-document-fields-javascript
For example, if you have a Page custom type with a parent
field that is a content relation field to another Page document, you can tell the API to return data for that relation. You can then use the link resolver to build the nested URL. The link resolver may look something like this:
const linkResolver =
(doc) => '/' + [doc.parent?.uid, doc.uid].filter(Boolean).join('/')
And the fetchLinks
plugin option would look like this:
{
resolve: 'gatsby-source-prismic',
options: {
// ...along with your other options...
fetchLinks: ['page.parent']
}
}
The actual link resolver logic would be specific to your project. But you can see there that you have access to the doc.parent
field.
Check out this issue on GitHub for more details: Custom URLs and Link Resolver · Issue #330 · angeloashmore/gatsby-source-prismic · GitHub