asLink(...) function with GraphQL data?

Has anyone been able to use "asLink(...)" function with GraphQL data? I want to link navigation link into specific document, but so far have not been able to do so. Noticed that the data what GraphQL returns is different versus what default Prismic API returns for "link_href" object.

That might cause the issue?

GraphQL returns following data:

"navigation_links": [
"link_name": "testi",
"link_href": {
"_linkType": "Link.document"

But default api returns following:


  • ["id"](javascript:;): "ZC7fehAAACIA-NRp",
  • ["type"](javascript:;): "home_landing_page",
  • ["tags"](javascript:;): ,
  • ["lang"](javascript:;): "en-gb",
  • ["slug"](javascript:;): "home---landing-page",
  • ["first_publication_date"](javascript:;): "2023-04-06T15:04:30+0000",
  • ["last_publication_date"](javascript:;): "2023-04-06T15:04:30+0000",
  • ["link_type"](javascript:;): "Document",
  • ["isBroken"](javascript:;): false


So previously I could just use "prismicH.asLink(link_href)" and no issue, but with GraphQL this is not the case. And been stuck on this quite some time, and not sure where the problem really is.

After long struggle, managed to fix this. Had to improvise when generating fragments with Codegen and then had to add some "custom" types when referencing the "_meta" inside "link_href" object.

Ill edit this message later, with my solution to fix this problem I had.

1 Like