DOCS: Advanced Querying with $prismic and using fetchLinks on one document by UID

Just wanted to offer this up because it was taking me for a little ride.

On this page:

There appears to be a typo (see screenshot at bottom) saying using

$'document.type', 'page'),
$'', 'about')

together will net you the page documents NOT where page.uid is about. At least for me this is not accurate and likely a typo where at() on the second predicate should be not().

Also, if you're looking to only select for the page at uid about, then the first predicate would be redundant and actually prevents me from using a { fetchLinks } object to include my content relationship.

What ended up working for me was

  async asyncData({ $prismic, params, error }) {
    const document = await $prismic.api.query(
      $'', params.uid),
      { fetchLinks: ['author.full_name', 'author.author_website'] }
    if (document) {
      return { post: document.results[0] }
    } else {
      error({ statusCode: 404, message: 'Page not found' })

Hello @james0r

Thanks for pointing this out to us. It's true that it should be not predicate instead at predicate.

To pull in content from another content, you can directly use query helpers getByUID instead of predicates for it. Here is the documentation.

Let me know if you have any further questions.


Thank you. That example would work, but I recommend there be an example for including things like authors, and it is a bit strange that that example is in the Templating Content page because in actuality that is querying content not templating it.

1 Like

Hello @james0r

Thanks for your feedback. fetchLinks is a query option and we have given that reference in the Performed Advanced Queries article. Surely, I consider your feedback and discuss it with the team to make it easily searchable.