prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
154 stars 40 forks source link

Link. url do not support graphql field return #31

Closed fchengpc closed 3 years ago

fchengpc commented 4 years ago

the prismic gql return object as following {"_linkType":"Link.web","__typename":"_ExternalLink"} then when you try to use link to render the url it throw

TypeError: Cannot read property 'link_type' of null
    at Object.url (webpack://PrismicReactjs/./node_modules/prismic-helpers/dist/prismic-helpers.min.js?:68:33)
hypervillain commented 4 years ago

Hey,

can you add some example code with ideally a request and an endpoint if it is public? I am not familiar with using GraphQL with Prismic

fchengpc commented 4 years ago

My bad, i lost track of this issue. here is some sample link fragment: {"_linkType":"Link.document","_meta":{"id":"XZvpkxIAACMAu8Vw","uid":"test--scheduler","__typename":"Meta"},"__typename":"Scheduler"}

import { Link } from 'prismic-reactjs';
export function RichLink(link) {
    return Link.url(link, linkResolver);
}

above code do not go into linkResolver

fchengpc commented 4 years ago

https://github.com/prismicio/prismic-reactjs/issues/37 might be the same issue

hypervillain commented 4 years ago

Ha, good catch. This one is actually an issue happening on several packages - we should check for both "Document" and "Link.Document"and same for "Link" I believe.

Do you want to take care of this one?

hypervillain commented 4 years ago

This PR should solve the issue: https://github.com/prismicio/prismic-helpers/pull/3

angeloashmore commented 4 years ago

Sounds like the fix for this is already in motion, but I am seeing the following different shapes for links in two different projects. Both use the REST API V2, but I think one of them might have GraphQL enabled on the repo (but unused).

Is this intentional? Sorry, I realize this is more of an API question than prismic-reactjs.

Project 1: Maybe with GraphQL enabled on the repo, but unused. Note the type: "Link.document"

{
  "type": "Link.document",
  "value": {
    "document": {
      "id": "XFyp-BAAACIAIod-",
      "type": "page",
      "lang": "en-us",
      "tags": [],
      "slug": "about",
      "uid": "people"
    }
  },
  "isBroken": false
}

Project 2: Without GraphQL enabled on the repo. Note the link_type: "Document"

{
  "id": "XZKZGxIAACQAZah3",
  "type": "page",
  "tags": [],
  "slug": "about",
  "lang": "en-us",
  "uid": "about",
  "link_type": "Document",
  "isBroken": false
}
hypervillain commented 3 years ago

Fixed by https://github.com/prismicio/prismic-helpers/pull/7