Let’s start from the top because I think you’re missing what I’m saying.
This is my query:
query NavMenu($uid: String!, $lang: String!) {
nav_menu(uid: $uid, lang: $lang) {
_meta {
uid
id
}
main_menu_items {
item {
... on Landing_page {
title
_linkType
_meta {
uid
id
}
}
}
}
topic_menu_items {
item {
_linkType
__typename
}
}
}
}
It reliably returns this output:
{
"data": {
"nav_menu": {
"_meta": {
"uid": "nav-menu",
"id": "XzwPtREAACAA8PUE"
},
"main_menu_items": [
{
"item": {
"title": [
{
"type": "heading1",
"text": "Policy",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "policy",
"id": "XzxF3REAACAA8eVf"
}
}
},
{
"item": {
"title": [
{
"type": "heading1",
"text": "Grants",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "grants",
"id": "XzxF8BEAACIA8eW6"
}
}
},
{
"item": {
"title": [
{
"type": "heading1",
"text": "Locations",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "locations",
"id": "XzxGLBEAACIA8ebD"
}
}
},
{
"item": {
"title": [
{
"type": "heading1",
"text": "Research",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "research",
"id": "XzxGPBEAACEA8ecS"
}
}
},
{
"item": {
"title": [
{
"type": "heading1",
"text": "Campaigns",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "campaigns",
"id": "XzxGTBEAACMA8edY"
}
}
},
{
"item": {
"title": [
{
"type": "heading1",
"text": "News",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "news",
"id": "XzxGXhEAACEA8eer"
}
}
},
{
"item": {
"title": [
{
"type": "heading1",
"text": "Events",
"spans": []
}
],
"_linkType": "Link.document",
"_meta": {
"uid": "events",
"id": "XzxGdBEAACIA8egQ"
}
}
}
],
"topic_menu_items": [
{
"item": {
"_linkType": "Link.document",
"__typename": "Topic"
}
},
{
"item": {
"_linkType": "Link.document",
"__typename": "Topic"
}
},
{
"item": {
"_linkType": "Link.document",
"__typename": "Topic"
}
},
{
"item": {
"_linkType": "Link.document",
"__typename": "Topic"
}
}
]
}
}
}
In the Prismic documentation, this is what is stated I should use for a linkResolver:
var PrismicDOM = require('prismic-dom');
var linkResolver = function(doc) {
// Pretty URLs for known types
if (doc.type === 'blog') return "/post/" + doc.uid;
if (doc.type === 'page') return "/" + doc.uid;
// Fallback for other types, in case new custom types get created
return "/doc/" + doc.id;
};
var html = PrismicDOM.RichText.asHtml(document.data.body, linkResolver);
If I independently call linkResolver
there is no doc
argument to pass in - just look at the response from the API. There aren’t any doc
fields and this is why it never works.
Take me through this step by step, like I’m five years old - how do I build a linkResolver for Next.js given this data structure? What’s going on inside of RichText
that it never works when I pass in linkResolver
? I’ve looked at the source for all of this and it too is so poorly documented I can’t figure out how to wire this stuff up.