verbb / navigation

A Craft CMS plugin to create navigation menus for your site.
Other
90 stars 23 forks source link

Add breadcrumb information to GraphQL queries #335

Open denisyilmaz opened 1 year ago

denisyilmaz commented 1 year ago

What are you trying to do?

To render breadcrumbs for a given entry it would be great to be able to query for the breadcrumbs.

What's your proposed solution?

Something like this:

{
  entry(id: 123) {
    breadcrumbs {
      title
      url
      segment
      elementId
      elementType
    }
  }
  breadcrumbs(id: 123) {
    title
    url
    segment
    elementId
    elementType
  }
}

Additional context

No response

engram-design commented 1 year ago

Two things of note - firstly nesting it within the entry interface might be tricky without creating a custom field that is owned by an entry. But it might be possible with a directive.

Secondly, determining the breadcrumbs of an entry really relies on the current URLs segments, which isn't going to be possible in a GraphQL query context (or headless in general). The current implementation will look at each segment in a URL, and if a segment matches the URI of an element, that's used, if not the segment (as a URL) is used.

I can see you're passing in an id param to represent the "current" entry/element for that purpose.